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
- total parameter not working correctly in...
Hello Appwrite team, I'm experiencing issues with the total parameter in the listRows() method (TablesDB) across multiple SDKs. **Issue 1**: Node.js SDK (node...
- Free plan Usage
I using a free plan with one organization. I have three projects but on the free plan I should be able to have 2 projects running But in my case only 1 out of ...
- Database AI Column Suggestion Use Case
I tried using the AI column suggestion feature. For me, I prefer writing my column design separately in a notepad. Then my intention is to paste it into the AI ...