我如何对Prisma中的某个条款进行计数?
我有以下查询,其中提供了所有帖子和所有评论的数量。现在,我想在帖子中获得所有评论,这些帖子将批准的字段设置为true。我似乎无法弄清楚。
prisma.post.findMany({
include: {
_count: { select: { Comment: true } },
},
});
感谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自 4.3.0 。
在模式文件中启用:
然后查询:
Available since 4.3.0.
enable in your schema file:
and then query:
您需要使用 _Count上的过滤器 in Resption>尚不支持将其实现。
这是相同的功能请求:能够过滤“计数关系”中的计数
[Edit: 14-Nov-2022]
Prisma has added support for filteredRelationCount since version
You would need to use Raw Query to achieve this as the filter on
_count
for relations is not supported yet.Here's the Feature Request for the same: Ability to filter count in "Count Relation Feature"
[Edit: 14-Nov-2022]
Prisma has added support for filteredRelationCount since version 4.3.0