Description
Describe the bug
This is mainly apparent in pagination, where you want the count of the primary objects. The count currently takes the count of all rows, which will include the joined rows. So if an object has many related objects, the count will be the number of related objects.
To Reproduce
Steps to reproduce the behavior:
I have added a test to check count in the "test_aggr" file on my forked branch, as well as some potential code to fix the issue.
I wasn't sure if you wanted to introduce a breaking change, or if the original functionality was necessary for something. I ended up changing the default, but adding a "distinct" keyword for those who depend on the legacy behavior.
Expected behavior
Count should return the count of the primary rows, not the total number of rows including left joins
Versions (please complete the following information):
- Postgres 11.4
- Python 3.8.11
- ormar 0.10.22
Activity
Fix collerek#588 Bug in queryset count() method
erichaydel commentedon Mar 9, 2022
Well my MR doesn't solve the problem because it fails on mysql. I'll work on getting that to work, but it's fairly hard for me to test on MYSQL.
EDIT: This is fixed
Fix collerek#588 Bug in queryset count() method
Fix collerek#588 documentation for distinct keyword to count method
Fix collerek#588 documentation for distinct keyword to count method
Merge pull request #589 from erichaydel/588-fix-queryset-count-bug