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
- [SOLVED] Appwrite Cloud and FRA cloud se...
Can anyone estimate how long this will take to resolve? I am checking status here https://status.appwrite.online/
- How to use Operator.arrayAppend on a rel...
Hi, is it possible to use any operator on a relationship column? I have a One to Many relationship column on a table and I would like to add entries to the colu...
- Terraform tablesdb_column type inconsist...
Hi, I am trying out the new terraform provider for appwrite that was introduced a few weeks back. As a first step I wanted to import our existing databases into...