Back

Multiple Relations in a collection

  • 0
  • Databases
krennih
17 Sep, 2023, 07:32

Hi, I am not sure if it's a bug or I did not really see through the new collection relations.

I have e.g. a collection holding reservations for a boat ride from a to b. I also have a ports collection and would need to have a portsfrom field referencing a port in reservations. So far so easy. That works!

Now I add another field that references the destination portsto in the same way and that keeps failing.

TL;DR
The user is experiencing issues with creating multiple relations in a collection. They have a "reservations" collection and a "ports" collection. The first relation, "portsfrom," works fine, but when they try to add another relation, "portsto," it fails. The problem is that both relations have the same column/attribute key, causing a conflict. The solution is to use a two-way relationship and configure the column/attribute keys in the related collection to be different. The user is advised to create an issue on GitHub with this information.
Drake
18 Sep, 2023, 16:58

would you please provide more detail on the attributes including one/two way and the attribute keys?

krennih
19 Sep, 2023, 16:05

Oh, sure… since every Reservation holds one reference to a Departure Port and one reference to a Destination Port I assume it is a many to one relation and it needs only to be one Way since the Ports dont need to store what Reservations they have. I provided a screenshot originally here https://discord.com/channels/564160730845151244/564160731327758347/1152573015201157170 but then forgot to copy it here https://cdn.discordapp.com/attachments/564160731327758347/1152573014735597618/Screenshot_2023-09-16_at_13.48.51.png

krennih
19 Sep, 2023, 16:07

The firt setup was exactly the same only the Attribute Key was different ´portfrom´. That first one was created well. https://cdn.discordapp.com/attachments/564160731327758347/1152573014978875452/Screenshot_2023-09-16_at_13.47.33.png

Drake
19 Sep, 2023, 19:34

ah very interesting...would you be able to create an issue and include this info in the issue?

The problem is a many to one relationship requires adding a column/attribute in the related collection. by default, the column/attribute key would be the source collection. however, the 2nd relationship would have the same column/attribute key causing the error

Drake
19 Sep, 2023, 19:36

if you use a two way relationship, you'll be able to configure the column/attribute key in the related collection, making it different, so they don't conflict

krennih
19 Sep, 2023, 19:37

sure I will post the issue and try using a two way relation for the 2nd Port reference. Thanks for looking into this!

krennih
20 Sep, 2023, 05:44

@Steven I tried the two-way-relation – unfortunately it does not work either. Also I raised the github issue

Drake
20 Sep, 2023, 17:23

Uh this is many to many now...

krennih
20 Sep, 2023, 20:08

😵‍💫 It's just not my day today ...

Drake
20 Sep, 2023, 20:08

would you please check the docker logs in the appwrite-worker-databases for this one?

krennih
20 Sep, 2023, 20:12

Ok, first it works with many to one. <:appwriteparty:946072712915341333>

krennih
20 Sep, 2023, 20:24

Here's what happens when I try to create the second Attribute: Like so?

krennih
20 Sep, 2023, 20:29

And this when I add the 2nd field in a many-to-many relation:

Drake
20 Sep, 2023, 20:33

you mean only creating the 1st attribute works?

Drake
20 Sep, 2023, 20:35

or did you mean these logs are from when you tried creating the one-way many to one?

Drake
20 Sep, 2023, 20:36

ok we should treat this as a separate issue: Unable to create multiple many to many relationships between the same collections

krennih
20 Sep, 2023, 20:45

🙈 My real life Problem is solved using your approach (Many-to-One in a two way Relationship wher I have PORTSFROM in Reservations related to RESERVATIONSTOHERE in the Ports Collection. The second field setting PORTSTO and RESERVATIONSTOHERE also works.

krennih
20 Sep, 2023, 20:45

The first log is when I repeat the initial problem.

krennih
20 Sep, 2023, 20:46

The second log is from the many-to-many issue. I can rais this on GitHub tomorrow separately.

btme0011
20 Sep, 2023, 21:21

Both attributes are two-way , many to one and their Attribute key of related collection is same ?

krennih
21 Sep, 2023, 05:49

I deleted them and readded them for logging purposes

Drake
22 Sep, 2023, 18:05

FYI, the related issue: https://github.com/appwrite/appwrite/issues/6281

Make sure you 👍🏼

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