简体   繁体   中英

How do I perform a count on a relation with a where clause in prisma?

I have the following query which gives all posts and a count of all comments. Now I'd like to get a count of all comments with the post that have the approved field set to true. I can't seem to figure this out.

prisma.post.findMany({
    include: {
      _count: { select: { Comment: true } },
    },
  });

Thanks for any help.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM