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
- Realtime for files() works almost well, ...
I have been trying to make use of realtime, today (14.03.26) I have pulled all the latest versions of docker images, and sdk available. Whats working: - Conn...
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Relation Question
How do I create a relation from table y to an others x.$id. in my example I have a users table where I use Appwrites unique User IDs and I want other tables fo...