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_appwriteversion^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:
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
- Create a document (parent) with an empty oneToMany relationship array
[] - Create a related document (child)
- Attempt to update the parent's oneToMany relationship with the child document ID:
We implemented a workaround that:
- Creates a temporary placeholder document in the related collection
- Updates the relationship with
[placeholderId, childDocumentId](2 items - this works!) - Deletes the placeholder document
- Updates the relationship again with
[childDocumentId](now works because array is no longer empty)
Recommended threads
- SELF HOSTING ISSUE, DATA NOT MIGRATING T...
Hey, devs, I recently tried to migrate my cloud instance to a self hosted version but my data is not transferred fully only the table structure is transferred ...
- No Document ID?
Hi I have a self hosted appwrite. My documents get a document ID but are not visible in the console. I don't know why this happens and how to fix this
- AppwriteException: Invalid query: Query ...
```js console.log(typeof interaction.user.id) console.log(interaction.user.id) const user_check = await TablesDB.listRows({ databaseId: "db", ...