Back

Relationship to the same collection

  • 0
  • Databases
theeugene
13 Mar, 2024, 18:51

For example, I have Followers collection. I want to add fields with the id of the user who is follower and the id of the user who is followed. ANd I want to use relationship for this to get any info about users when I'll fetch data. So my structure must be like this:

id (string) user_id (relationship to users | one way - many to one) follow_id (relationship to users | one way - many to one)

But problem is I can't use relationship to the same collection. So may be my logic is wrong and I need to do it another way? But I think it would be very convenient and logical to do it this way.

TL;DR
To establish relationships between users and their followers in a collection, you can create separate collections for Users and Followers. Inside the Followers collection, include attributes for the follower's ID and the user being followed's ID. While you can't directly set up relationships in the same collection, you can still link the IDs. This structure allows you to efficiently fetch user data.
D5
13 Mar, 2024, 18:58

You need to have multiple collections for this case:

  • Users (here the name, etc)
  • Followers

Inside the followers you have 2 attributes: the ID from the one that follows and another attribute for the ID from the one that is being followed

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