I would like to know how can I use multiple filter with Prisma 2 when almsot one filter is an relation. I search one post with specific ID and specific author (security reason).
I read the documentation and I try to apply with this :
const postExists = await prisma.post.findMany({
where: {
AND: [
{
id: {
equals: parseInt(args.id, 10), // args.id => 770
},
},
{
author: {
id: {
equals: parseInt(userId, 10), // userId => 584
},
},
},
],
},
})
In my database I have this :
But I found my post if I'm not the author (for example, author id 1)
const postExists = await prisma.post.findMany({
where: {
AND: [
{
id: {
equals: parseInt(args.id, 10), // args.id => 770
},
},
{
author: {
id: {
equals: parseInt(userId, 10), // userId => 1
},
},
},
],
},
})
In my schema.prisma I have this :
model Post {
content String?
createdAt DateTime @default(now())
fk_user_id Int
id Int @default(autoincrement()) @id
published Boolean @default(false)
title String
author User @relation(fields: [fk_user_id], references: [id])
@@index([fk_user_id], name: "fk_user_id")
}
model User {
email String @unique
id Int @default(autoincrement()) @id
name String?
password String @default("")
Post Post[]
Profile Profile?
}
