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...
1 parent 93b4199 commit 6678de130c9539d2103b5c72561c0869f0d838d7 @malcolmt malcolmt committed Oct 14, 2007
Showing with 9 additions and 1 deletion.
  1. +5 −1 django/db/models/sql/query.py
  2. +4 −0 tests/regressiontests/queries/models.py
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>]
"""}

0 comments on commit 6678de1

Please sign in to comment.