Quick question -- if I want to get all of the upvo...
# orm-help
j
Quick question -- if I want to get all of the upvotes and downvotes from
Users
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:
Copy code
model Post {
  id         Int @id @default(autoincrement())
  upvotes    User[]
  downvotes  User[]
}

model User {
  id Int @id @default(autoincrement())
  upvotes Post[]
  downvotes Post[]
}
m
try
Copy code
model 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[]
}