diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-04-13 04:42:08 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-04-13 04:42:08 +0000 |
| commit | 01b7a16ef0e3b11c7a2cbee5ec4a73251664d1c5 (patch) | |
| tree | 6a7e5eb9a2c9851b4124e5757ec8faa530058c34 | |
| parent | ed23f00a0007116a695adadc53d642ab90823823 (diff) | |
queryset-refactor: When using select_related() with an explicit foreign key,
use the right join type if the FK is nullable. Fixed #6981.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7418 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/sql/query.py | 6 | ||||
| -rw-r--r-- | tests/regressiontests/queries/models.py | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 34b3c530b3..80ec236edb 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -793,11 +793,13 @@ class Query(object): lhs_col = int_opts.parents[int_model].column int_opts = int_model._meta alias = self.join((alias, int_opts.db_table, lhs_col, - int_opts.pk.column), exclusions=used) + int_opts.pk.column), exclusions=used, + promote=f.null) else: alias = root_alias alias = self.join((alias, table, f.column, - f.rel.get_related_field().column), exclusions=used) + f.rel.get_related_field().column), exclusions=used, + promote=f.null) used.add(alias) self.select.extend([(alias, f2.column) for f2 in f.rel.to._meta.fields]) diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 39f13d616d..f80d1eb827 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -561,6 +561,10 @@ Multiple filter statements are joined using "AND" all the time. >>> Author.objects.filter(Q(extra__note=n1)|Q(item__note=n3)).filter(id=a1.id) [<Author: a1>] +Bug #6981 +>>> Tag.objects.select_related('parent').order_by('name') +[<Tag: t1>, <Tag: t2>, <Tag: t3>, <Tag: t4>, <Tag: t5>] + Bug #6180, #6203 >>> Item.objects.count() 4 |
