Hi, I have a schema akin to this. I have a need w...
# orm-help
s
Hi, I have a schema akin to this. I have a need where I need to fetch all posts by
id
of the user as well as the
uuid
.
Copy code
model User {
  id    Int    @id @default(autoincrement())
  uuid  String @default(cuid())
  posts Post[]
}

model Post {
  id       Int  @id @default(autoincrement())
  author   User @relation(fields: [authorId], references: [id])
  authorId Int
}
I get all the posts by authorId by this. How can I do something similar also with UUID?
Copy code
const event = await prisma.posts.findMany({
    where: {
      authorId: 1
    }
  });
b
I don’t quite understand your query findUnique will return 1 post and not all posts. and you cannot pass authorId either because that’s not a unique field
Copy code
const event = await prisma.post.findUnique({
  where: {
    id: 1,
  }
});
would be the correct query to return the post with ID:1
n
It seems you would need to use
findMany
to get all the posts, you can use this query
Copy code
const event = await prisma.post.findMany({
    where: {
      id: 1,
      authorId: 1,
      author: {
        uuid: 'cef9f8f8-f8f8-f8f8-f8f8-f8f8f8f8f8f',
      },
    },
  });
👍 1
s
Yeah, sorry about that.
Thank you. Will give this a try.