dabapps / django-rest-framework-serialization-spec

DEPRECATED, see https://github.com/dabapps/django-readers instead
MIT License
11 stars 0 forks source link

Make Count distinct by default #30

Closed pmg103 closed 4 years ago

pmg103 commented 4 years ago

https://github.com/dabapps/django-rest-framework-serialization-spec/issues/27

By default use distinct=True on Count() so that multiple Counts don't interfere with each other

As per https://docs.djangoproject.com/en/2.2/topics/db/aggregation/#combining-multiple-aggregations:

Combining multiple aggregations with annotate() will yield the wrong results because joins are used instead of subqueries ... For most aggregates, there is no way to avoid this problem, however, the Count aggregate has a distinct parameter that may help