Douglas
07/16/2021, 9:20 PMMahmoud
07/16/2021, 9:21 PMDouglas
07/16/2021, 9:33 PMmodel Follows {
follower User @relation("follower", fields: [followerId], references: [id])
followerId Int
following User @relation("following", fields: [followingId], references: [id])
followingId Int
@@id([followerId, followingId])
}
model User {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
followers Follows[] @relation("follower")
following Follows[] @relation("following")
}
But where I have also added a field for
model Follows {
// how many times the person has been clicked
clicked Int
...
So in the end, I think this solves things? I guess the only thing I might want to change is that I don't want to know if someone has any followers, simply how many times they have clicked a specific user.Douglas
07/16/2021, 9:36 PMDouglas
07/16/2021, 9:36 PMDouglas
07/16/2021, 9:41 PMChris Tsongas
07/16/2021, 10:42 PMDouglas
07/17/2021, 1:16 PMGiuseppe
07/18/2021, 8:32 PMmodel User {
id String @id @default(cuid())
following User[] @relation(name: "UserFollows")
followers User[] @relation(name: "UserFollows")
}
is this a bad idea? Would it be better to have a separate model for this and store (and maintain) the count on User
(for perf reasons?)Giuseppe
07/18/2021, 8:33 PMGiuseppe
07/18/2021, 8:33 PMGiuseppe
07/18/2021, 8:35 PMDaniel Norman
model Follows {
follower User @relation("follower", fields: [followerId], references: [id], onDelete: Cascade)
followerId Int
followee User @relation("followee", fields: [followeeId], references: [id], onDelete: Cascade)
followeeId Int
@@id([followerId, followeeId])
}
model User {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
followers Follows[] @relation("follower")
followees Follows[] @relation("followee")
}
I just tested and the selecting relation counts works with this approach.Giuseppe
07/19/2021, 3:52 PM