Hi, could anyone give me some pointers to how I ca...
# orm-help
n
Hi, could anyone give me some pointers to how I can add something like likes, liked, follows, and followers to datamodel.prisma in terms of creating a social media app? For example I have a user model like below: I have newly added likes, follows, and followers, but prisma asks me to add relationship.
Copy code
type User {
    id: ID! @unique
    username: String! @unique
    likes: [Item!]!
    follows: [User!]!
    followers: [User!]!
    categories: [Category!]! @relation(name: "CategoryToUser", onDelete: CASCADE)
    items: [Item!]! @relation(name: "ItemToUser", onDelete: CASCADE)
    comments: [Comment!]! @relation(name: "CommentToUser", onDelete: CASCADE)
    ...
}
What is the best way to set up relations for likes, follows, followers as the items do not usually belong to the user him/herself? or better to do like below? (just keep user or item ids).
Copy code
likes: [ID!]!
 follows: [ID!]!
 followers: [ID!]!
and add some logic in the node server?
s
Users won't "like" other users. Users will 'like' Post (in your case it's item) so "likes" relation belongs in "Item"
Copy code
type Item {
id: ID! @unique
likes: [User!]
}
n
Yes, I have item like below:
Copy code
type Item {
    id: ID! @unique
    title: String!
    tags: [String!]!
    liked: [User!]!
    ...
}
But, this feels not enough as I cannot find likes of a specific user quickly.
t
I think it’s the same question I asked above, when queryieng the relation, you don’t get the foreign key, so it’s hard to query the related list on the resolver
I had to do something like this
Copy code
const [group] = await prisma.rulesGroups({
      where: { rules_some: { id: parent.id } },
    });