Hi, Had a question about foreign key. Suppose I w...
# orm-help
s
Hi, Had a question about foreign key. Suppose I wanted a post with id : 1 and user : 1 (user being parent), how would I go about it?
Copy code
const event = await prisma.posts.findUnique({
    where: {
      id: 1
    }
  });
a
What does your schema look like for
Posts
s
Copy code
model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}

model Post {
  id       Int  @id @default(autoincrement())
  author   User @relation(fields: [authorId], references: [id])
  authorId Int
}
Something like this.
a
Copy code
const event = await prisma.posts.findUnique({
    where: {
      id: 1,
      authorId: 1
    }
  });
👍 1