Scratchyone Scratchyone
06/15/2021, 2:03 AMRyan
06/15/2021, 5:23 AMmodel Post {
id Int @id @default(autoincrement())
title String
votes Vote[]
}
model Vote {
id Int @id @default(autoincrement())
post Post? @relation(fields: [postId], references: [id])
postId Int?
}
Do you want something like this?
[
{ title: "post 1", votes: { _count: 100 }
]Ryan
06/15/2021, 5:25 AMawait prisma.post.findMany({
include: { _count: { select: { votes: true } } },
})Scratchyone Scratchyone
06/15/2021, 12:24 PMScratchyone Scratchyone
06/15/2021, 12:25 PMScratchyone Scratchyone
06/15/2021, 12:26 PMScratchyone Scratchyone
06/15/2021, 12:41 PM