Ability to filter count in "Count Relation Feature"
See original GitHub issueProblem
Currently count relation feature just accepts true
or false
values and count all the related records.
Sometimes we just need to count some of the records depends on the query.
For example
this.prisma.groupExamAttempt.findMany({
where: {
groupId: param.groupId,
examId: param.examId,
},
include: {
_count: {
select: {
answers: true,
},
},
},
});
This will just passively count all the records there.
Suggested solution
To filter maybe we can add a where clause
this.prisma.groupExamAttempt.findMany({
where: {
groupId: param.groupId,
examId: param.examId,
},
include: {
_count: {
select: {
answers: {
where: {
isCorrect: true,
},
},
},
},
},
});
Maybe if applicable, It can also be based on the deeper relationship filter. (IF ONLY THIS IS DOABLE)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:78
- Comments:22 (4 by maintainers)
Top Results From Across the Web
Count filter use relationship - Microsoft Power BI Community
I have opportunity records that have a primary contact. ... Measure = CALCULATE ( COUNT ( 'Campaign Responses'[Campaign Name] ), FILTER ...
Read more >How do I perform a count on a relation with a where clause in ...
Here's the Feature Request for the same: Ability to filter count in "Count Relation Feature". [Edit: 14-Nov-2022].
Read more >How to Filter Records with Aggregate Function COUNT
To filter records according the given number of rows in the group, use the HAVING clause. It filters rows using in a condition...
Read more >Count rows in a filtered list - Honeycode Community
The summary table solution will allow you to show a count for each name and filter out any count that is 0. The...
Read more >COUNT() SQL FUNCTION - DataCamp
COUNT () , used with HAVING , is useful for filtering groups according to the number of rows they have. We will illustrate...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Running into a need for this too. Would love to be able to do something like e.g. find users with >50 followers
This is also pretty essential for soft deletes. Ex. no reason for deleted records to be included in the count.