Back

Unable to create multiple one-to-one relationships between two collections.

  • 0
  • Databases
  • Flutter
Bichkar
13 Dec, 2023, 18:40

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?

TL;DR
The user is experiencing an issue when trying to create multiple one-to-one relationships between two collections in Appwrite. They are getting a server error and are unsure of what is wrong. Another user suggests that there may be a conflict with the column name and advises specifying the related key. The user has suspended development and is waiting for a solution from the Appwrite team. One user recommends creating a feature request on GitHub. It is clarified that relationships are between two documents, not specific attributes within documents. The user is creating a Flutter application with a contact collection that includes mobile, email, and address fields. They want each address field to have a
ideclon
13 Dec, 2023, 18:49

Relationships are between two Documents, not specific Attributes within Documents

Bichkar
13 Dec, 2023, 19:38

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?

ideclon
13 Dec, 2023, 19:50

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+).

ideclon
13 Dec, 2023, 19:51

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.

Bichkar
14 Dec, 2023, 19:05

Thank you very much for your reply.

Drake
15 Dec, 2023, 20:52
Drake
15 Dec, 2023, 20:58

sooooo did you create a one-way or two-way relationships?

Bichkar
17 Dec, 2023, 05:35

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.

Drake
17 Dec, 2023, 08:12

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

Bichkar
17 Dec, 2023, 09:38

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.

Bichkar
17 Dec, 2023, 12:09

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.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more