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
- TablesDB `updateRows` returns `database_...
Hi Appwrite team! I’m seeing a strange issue with TablesDB bulk row updates on a self-hosted Appwrite instance. **Environment** - Appwrite self-hosted `1.9.0` ...
- Update row sheet not loading
After right clicking a row header and click update, the sidebar fails to load (never-ending skeleton)
- DB Relational Table Request
Hi, I'd like to suggest a rewording of the relationships between tables. - Current wording: storeOperatingDays can contain one storeId ...