Unable to create multiple one-to-one relationships between two collections.
- 0
- Databases
- Flutter
I am creating a Flutter application containing the following data: Contact (of a person) containing mobile, email, permanent address, local address, communication address, etc.
I have created two collections namely, contact and address. The contact has the following fields: mobile, email, permAddr (permanent address), localAddr (local address), and commAddr (communication address), etc. Each of the address fields are expected to have one-to-one relation to the address collection. However, it is not possible to create three one-to-one relations between contact and address collections. I get the 'failed' error in the console when I create second and third one-to-one relations.
It is possible to create one-to-many relationship. However, it will require 'address' relation field to be an array, which I do not want. I wish to keep these three fields separate as mentioned above.
How to handle this situation?
Relationships are between two Documents, not specific Attributes within Documents
Thank you very much. Does it mean that the specific example cited above cannot be handled by Appwrite? Shall I put a request in github for including this support in AppWrite?
There's a currently open Pull Request to prevent creating multiple Relationships between the same Collections (instead of just getting failed
, as you do now). However, I would assume this is more of a UX thing than a will to not allow it. So I would say yes, do create a Feature Request (https://github.com/appwrite/appwrite/issues/new?assignees=&labels=feature&projects=&template=feature.yaml&title=%F0%9F%9A%80+Feature%3A+).
I wouldn't expect it to come very soon, though, as from my understanding, this would require a rework of how Relationships are represented in Appwrite.
Thank you very much for your reply.
The new issue: https://github.com/appwrite/appwrite/issues/7288
sooooo did you create a one-way or two-way relationships?
I wanted to create one-way relationship. But the application needs to have multiple one-way relationships between two collections. I have suspended the development for the time-being and awaiting for the solutions from the Appwrite team.
Soo think you're facing the problem in this issue: https://github.com/appwrite/appwrite/issues/6281. The problem is there is still a column added to the related table and if you don't specify the column name, it causes a conflict. So, for now, you'd have to create two way relationships and specify the related key. You can also try to see if you can specify the related key if you make the API call manually
Thanks a lot. I could create multiple relationships (two one-way relationships: one-to-one and one-to-many and one two-way relationship). Theoretically this should work. But I will test the code and report the outcome.
I could also create multiple two-way one-to-one relationships for each of the contained address fields, namely, permAddr, localAddr and commAddr. However, I am still unable to put it to work. When I try to save Contact record, I am getting 'Server error'. Unable to find whats wrong as the JSON provided for Contact seems to be correct. (I am providing data as a nested JSON, without ids for the contained fields). The children address documents are created but the main contact document is not created.