Jon
02/02/2022, 7:23 PMUsers
per Post
OR get all of the upvotes and downvotes per User
how would I construct the schema? I've tried a bunch of permutations but can't figure out how to do the relations:
model Post {
id Int @id @default(autoincrement())
upvotes User[]
downvotes User[]
}
model User {
id Int @id @default(autoincrement())
upvotes Post[]
downvotes Post[]
}
matic
02/02/2022, 7:27 PMmatic
02/02/2022, 7:27 PMmodel Post {
id Int @id @default(autoincrement())
votes Vote[]
}
enum VoteKind {
UP
DOWN
}
model Vote {
kind VoteKind
post Post @relation(fields: [postId], references: [id])
postId Int
user User @relation(fields: [userId], references: [id])
userId Int
@@unique([postId, userId])
}
model User {
id Int @id @default(autoincrement())
votes Vote[]
}