I want to create a relationship in my "Users" collection that'll point to it's own self. Tho I'm not building a social media app, but you can think of it as the friends list of a user in a social media network. So each user doc will need a relationship named "friends" to its own collection ("Users" in this case), cuz each "friend" is also a user. When I try doing it from the console, I can't find the "Users" collection under the "Related Collection" search box.
I don't know if I was clear enough... Let me know if you want more details
Ya...you can't at the moment. You can either create a friendship collection and then have relationship attributes to the user collection.
wouldn't it make it harder to manage? and what will the friendship collection contain?
I don't think so. I also usually avoid arrays because Appwrite doesn't support array operations
what the friendship collection should contain?
A two way many to one. This would allow you to see all the friends a user has from the user collection. Then, a one way many to one. Actually...this works more for a follower following scenario 🤔
do you mean, that whoever is added as a friend to anyone, should be added to the "friends" collection with a two-way many-to-one relationship with "Users"?
Yes, but there should be two attributes.
Maybe two documents should be added for each triend
about attributes, we need to store all the necessary info of the friend along with the relationship attribute. is there any more important attribute in your mind?
Maybe two documents should be added for each triend why two documents?
So that you can make 1 query to get all the friends of a user
if we do two-way many-to-many, then can't we just get all the friends of a user directly from the user doc? only need to get the corresponding user document and read the "friends" attribute?
sure i guess.
[SOLVED] How to create relationship within the same collection?
Recommended threads
- Type Mismatch in AppwriteException
There is a discrepancy in the TypeScript type definitions for AppwriteException. The response property is defined as a string in the type definitions, but in pr...
- What Query's are valid for GetDocument?
Documentation shows that Queries are valid here, but doesn't explain which queries are valid. At first I presumed this to be a bug, but before creating a githu...
- Appwrite exception: user_unauthorized, t...
After refreshing the app it is working perfectly