如何过滤 Prisma 中的相关对象?
How to filter for related objects in Prisma?
如何在 Prisma 中查询关系?我有以下架构:
model User {
id Int @id @default(autoincrement())
name String?
profile Profile
}
model Profile {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int
}
如何查询 Profile
以获得特定的 User
?
自己找到答案:
prisma.user.findUnique({ where: { id: 42 }}).profile()
如何在 Prisma 中查询关系?我有以下架构:
model User {
id Int @id @default(autoincrement())
name String?
profile Profile
}
model Profile {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int
}
如何查询 Profile
以获得特定的 User
?
自己找到答案:
prisma.user.findUnique({ where: { id: 42 }}).profile()