Vignesh
05/31/2021, 8:40 PMSELECT id, name from posts where id IN (select post_id from comments where user_id='123');Omar Hamdan
06/01/2021, 12:48 AMOmar Hamdan
06/01/2021, 12:49 AMVignesh
06/01/2021, 5:13 AMRyan
06/01/2021, 6:17 AMmodel User {
id Int @id @default(autoincrement())
name String
posts Post[]
comments Comment[]
}
model Post {
id Int @id @default(autoincrement())
title String
comments Comment[]
user User? @relation(fields: [userId], references: [id])
userId Int?
}
model Comment {
id Int @id @default(autoincrement())
comment String
author User? @relation(fields: [userId], references: [id])
post Post? @relation(fields: [postId], references: [id])
postId Int?
userId Int?
}
It could be done as follows:
await prisma.comment.findMany({
where: { userId: 123 },
include: { post: true },
})Vignesh
06/01/2021, 6:20 AMRyan
06/01/2021, 6:21 AMselect then instead of include and specify the required fields.