Hello there, just searching for some ideas on how ...
# orm-help
j
Hello there, just searching for some ideas on how to implement a friendship system. So i have this datamodel:
Copy code
type User {
  id: ID! @unique
  email: String @unique
  username: String @unique
  password: String!
  firstname: String
  lastname: String
  createdAt: DateTime!
  updatedAt: DateTime!
  friends: [Friendship!]!
}


type Friendship{
  id: ID! @unique
  createdAt: DateTime!
  users: [User!]!
}
and each user has an array of Friends. So I was thinking to implement it like the users of the people that array, but kinda went and using like the relation with Friendship table since i may want to know when they became friends etc, so the output of that is something like [idUser1, idUser2] and inside the user there is an array with the Ids of this record in Friendship table where the values are saved. Maybe this isn't the best way, in pure SQL i would have done something like the friendship table and saving user1 and user2 without the other fields
c
I did something similar but I directly associated users as friends
but then have an actions field, similar to your friendship field
where they would have action "befriended" and a link to the creator of the action and the other user
this let me easily get the list of friends on both parties
but also see when they friended, who did it and when, and also if they defriended
because yours seems like it will make kind of a worse query in the end
since every friendship is just two people, so querying all your friends seems like a big join I dunno though
not sure if my way is right or wrong
I use my actions for all sorts of actions since I have a feed
befriending is just one(in my case its following, but pretty much the same thing)