Warm tip: This article is reproduced from serverfault.com, please click

How to filter for related objects in Prisma?

发布于 2020-11-29 16:17:53

How can query relationships in Prisma? I have the following schema:

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
}

How can I query a Profile for a specific User?

Questioner
nburk
Viewed
0
nburk 2020-11-30 00:24:56

Found the answer myself:

prisma.user.findUnique({ where: { id: 42 }}).profile()