mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
[soc2009/multidb] Fixed the usage of the connection during Query construction, and defer it until actual SQL construction. In practice this means the GROUP BY optimization we do will be correctly applied based on the connection the Query is executed against, as oppossed to the on the QuerySet is targeting at the time the GROUP BY items are added
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@10934 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -878,6 +878,9 @@ class BaseQuery(object):
|
||||
qn = self.quote_name_unless_alias
|
||||
result, params = [], []
|
||||
if self.group_by is not None:
|
||||
if len(self.model._meta.fields) == len(self.group_by) and \
|
||||
self.connection.features.allows_group_by_pk:
|
||||
self.group_by = [(self.model._meta.db_table, self.model._meta.pk.column)]
|
||||
group_by = self.group_by or []
|
||||
|
||||
extra_selects = []
|
||||
@@ -2099,11 +2102,6 @@ class BaseQuery(object):
|
||||
will be made automatically.
|
||||
"""
|
||||
self.group_by = []
|
||||
if self.connection.features.allows_group_by_pk:
|
||||
if len(self.select) == len(self.model._meta.fields):
|
||||
self.group_by.append((self.model._meta.db_table,
|
||||
self.model._meta.pk.column))
|
||||
return
|
||||
|
||||
for sel in self.select:
|
||||
self.group_by.append(sel)
|
||||
|
||||
Reference in New Issue
Block a user