1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

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
This commit is contained in:
Malcolm Tredinnick 2008-04-13 04:42:08 +00:00
parent ed23f00a00
commit 01b7a16ef0
2 changed files with 8 additions and 2 deletions

View File

@ -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])

View File

@ -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