Skip to content
Back

Cannot Update Empty oneToMany Relationships

  • 0
  • Databases
Belly
30 Dec, 2025, 12:40

Appwrite's updateDocument() API cannot update an empty oneToMany relationship array. When attempting to update an empty relationship with a single-item array, the API returns a relationship_value_invalid error with contradictory error messages.

Environment

  • Appwrite Version: Cloud (cloud.appwrite.io)
  • SDK: dart_appwrite version ^20.1.0
  • Dart SDK: >=3.0.0 <4.0.0
  • Relationship Type: oneToMany

Expected Behavior

When a oneToMany relationship array is empty [], we should be able to update it with a single-item array [documentId] to add the first relationship.

Actual Behavior

When attempting to update an empty oneToMany relationship with a single-item array, Appwrite rejects the update with:

TypeScript
AppwriteException: relationship_value_invalid, Invalid relationship value. 
Must be either a document, document ID or null. Array given. (400)

However, the error message is contradictory because:

  • When passing an array: "Must be either a document, document ID or null. Array given."
  • When passing a single document ID: "Must be either an array of documents or document IDs, string given."
  • When passing a document object: "Must be either an array of documents or document IDs, object given."
  • When passing null: "Must be either an array of documents or document IDs, NULL given."

This creates a catch-22 situation where no format is accepted when the relationship is empty.

Steps to Reproduce

  1. Create a document (parent) with an empty oneToMany relationship array []
  2. Create a related document (child)
  3. Attempt to update the parent's oneToMany relationship with the child document ID:

We implemented a workaround that:

  1. Creates a temporary placeholder document in the related collection
  2. Updates the relationship with [placeholderId, childDocumentId] (2 items - this works!)
  3. Deletes the placeholder document
  4. Updates the relationship again with [childDocumentId] (now works because array is no longer empty)
TL;DR
Cannot update an empty oneToMany relationship array in Appwrite due to an error with contradictory messages. Workaround: create a placeholder document, update with `[placeholderId, childDocumentId]`, delete placeholder, update with `[childDocumentId]`.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more