shahrukh ahmed
05/11/2022, 7:53 AMid of the user as well as the uuid.
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?
const event = await prisma.posts.findMany({
where: {
authorId: 1
}
});Benjamin Indermühle
05/11/2022, 8:22 AMBenjamin Indermühle
05/11/2022, 8:24 AMconst event = await prisma.post.findUnique({
where: {
id: 1,
}
});
would be the correct query to return the post with ID:1Nurul
05/11/2022, 8:25 AMfindMany to get all the posts, you can use this query
const event = await prisma.post.findMany({
where: {
id: 1,
authorId: 1,
author: {
uuid: 'cef9f8f8-f8f8-f8f8-f8f8-f8f8f8f8f8f',
},
},
});shahrukh ahmed
05/11/2022, 8:25 AMshahrukh ahmed
05/11/2022, 8:26 AM