Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

queryset-refactor: Fixed handling of extra(tables=...). In passing, t…

…his solves

a duplicate table / bad SQL problem. Refs #2496.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6504 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6678de130c9539d2103b5c72561c0869f0d838d7 1 parent 93b4199
@malcolmt malcolmt authored
View
6 django/db/models/sql/query.py
@@ -371,7 +371,11 @@ def get_from_clause(self):
qn(lhs_col), qn(alias), qn(col)))
else:
result.append('%s%s' % (qn(name), alias_str))
- result.extend(self.extra_tables)
+ extra_tables = []
+ for t in self.extra_tables:
+ alias, created = self.table_alias(t)
+ if created:
+ result.append(', %s' % alias)
return result, []
def get_grouping(self):
View
4 tests/regressiontests/queries/models.py
@@ -202,5 +202,9 @@ def __unicode__(self):
[<Author: a3>]
>>> Tag.objects.filter(item__isnull=True)
[<Tag: t5>]
+
+Bug #2496
+>>> Item.objects.extra(tables=['queries_author']).select_related().order_by('name')[:1]
+[<Item: four>]
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.