gpt4 book ai didi

prisma - 您如何使用 Prisma 过滤没有相关记录的记录?

转载 作者:行者123 更新时间:2023-12-02 19:10:00 25 4
gpt4 key购买 nike

以 Prisma 文档中的架构为例,我想查询 Users 以查找没有任何 posts 的任何用户。我可以像这样破解它,以便它检索所有帖子的 ID 都不大于 0 的每个用户,但这不是很优雅。有更好的方法吗?

const result = await prisma.user.findMany({
where: {
post: {
none: {
id: { gt: 0 }
}
}
}
})

最佳答案

你可以这样做:

prisma.user.findMany({ where: {
posts: { none: {} }
}})

关于prisma - 您如何使用 Prisma 过滤没有相关记录的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64438621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com