selecting a count of relations, like in this API e...
# orm-help
t
selecting a count of relations, like in this API example, is there a way to filter the counted rows? say, if you have a
deleted
column in posts and only want to count the non-deleted posts? https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#include-a-_count-of-relations
a
Hi Tom 👋. Happy to see you in our community! Have you looked at our aggregate API? It might be able to accomplish what you are looking for in a slightly different way. Something like:
Copy code
const count = await prisma.post.aggregate({
  _count: true,
  where: { deleted: false }
})
👋 1
t
That would work for counting all non-deleted posts, but not for showing, say, a list of authors with how many (non-deleted) posts they have, right?
Or I'd have to do that per row and have n queries
Doing a second group by query with
in
could maybe express this in 2 queries, but seems hacky
a
Yes, you are right, it would take multiple queries (or the use of
$queryRaw
) to get that specific result. If you are interested in seeing filtering on relation counts, please add your use case/+1 on this feature request.
✅ 1