mirror of
https://github.com/django/django.git
synced 2025-12-02 00:01:29 +00:00
Fixed #28399 -- Fixed QuerySet.count() for union(), difference(), and intersection() queries.
This commit is contained in:
parent
9290f15bb5
commit
adab280cef
5 changed files with 39 additions and 11 deletions
|
|
@ -411,12 +411,12 @@ class Query:
|
|||
# aren't smart enough to remove the existing annotations from the
|
||||
# query, so those would force us to use GROUP BY.
|
||||
#
|
||||
# If the query has limit or distinct, then those operations must be
|
||||
# done in a subquery so that we are aggregating on the limit and/or
|
||||
# distinct results instead of applying the distinct and limit after the
|
||||
# aggregation.
|
||||
# If the query has limit or distinct, or uses set operations, then
|
||||
# those operations must be done in a subquery so that the query
|
||||
# aggregates on the limit and/or distinct results instead of applying
|
||||
# the distinct and limit after the aggregation.
|
||||
if (isinstance(self.group_by, tuple) or has_limit or has_existing_annotations or
|
||||
self.distinct):
|
||||
self.distinct or self.combinator):
|
||||
from django.db.models.sql.subqueries import AggregateQuery
|
||||
outer_query = AggregateQuery(self.model)
|
||||
inner_query = self.clone()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue