https://www.prisma.io/ logo
#orm-help
Title
# orm-help
f

Fergal Moran

09/29/2022, 7:02 PM
Hello all, I'm trying to use the preview filteredRelationCount feature and I have a question. How can I perform two counts on the same column with a different filter?
Copy code
const items = await prisma.items.findMany({
    take: 12, orderBy: { title: 'asc' },
    include: {
        _count: {
            select: {
                votes: { where: { isUp: true } },
                votes: { where: { isUp: false } }, // ???
            }
        }
    }
});
like, I would like the two votes fields to be "upVotes" and "downVotes"? Thanks for any help!
1
n

Nurul

09/30/2022, 11:59 AM
Hey @Fergal Moran 👋 It seems you would need to create two separate queries, one for upvotes and the other for downvotes. For this use case, using AND or OR operators will also not be ideal.
😵 1
f

Fergal Moran

09/30/2022, 1:36 PM
Ok... thanks @Nurul
3 Views