Skip to content
Browse files

queryset-refactor: Fixed problems with values() queries across nullab…

…le relations.

git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7287 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 67cc3ce commit bec21f0e2b5ab44565066cdab25ec6746d96efcc @malcolmt malcolmt committed Mar 18, 2008
Showing with 14 additions and 1 deletion.
  1. +14 −1 django/db/models/sql/query.py
View
15 django/db/models/sql/query.py
@@ -1171,7 +1171,20 @@ def add_fields(self, field_names, allow_m2m=True):
u1, target, u2, joins, u3 = self.setup_joins(
name.split(LOOKUP_SEP), opts, alias, False, allow_m2m,
True)
- self.select.append((joins[-1], target.column))
+ final_alias = joins[-1]
+ col = target.column
+ if len(joins) > 1:
+ join = self.alias_map[final_alias]
+ if col == join[RHS_JOIN_COL]:
+ self.unref_alias(final_alias)
+ final_alias = join[LHS_ALIAS]
+ col = join[LHS_JOIN_COL]
+ joins = joins[:-1]
+ for join in joins[1:]:
+ # Only nullable aliases are promoted, so we don't end up
+ # doing unnecessary left outer joins here.
+ self.promote_alias(join)
+ self.select.append((final_alias, col))
except MultiJoin:
raise FieldError("Invalid field name: '%s'" % name)

0 comments on commit bec21f0

Please sign in to comment.
Something went wrong with that request. Please try again.