【发布时间】:2020-10-13 19:01:55
【问题描述】:
我想知道当一个过滤器是一个关系时,如何在 Prisma 2 中使用多个过滤器。我搜索了一篇具有特定 ID 和特定作者(安全原因)的帖子。
我阅读了documentation 并尝试申请:
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
},
},
},
],
},
})
在我的数据库中我有这个:
但如果我不是作者,我找到了我的帖子(例如,作者 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
},
},
},
],
},
})
在我的 schema.prisma 我有这个:
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?
}
【问题讨论】:
标签: node.js apollo-server prisma