diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-03-14 11:46:26 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-03-14 11:46:26 +0000 |
| commit | 59ac04a54dde3a489f7948b6e6d6170d74aa80c8 (patch) | |
| tree | 43d77b2f93aa8def72a69eff18ac1cec2da48f12 /django/db/models/sql | |
| parent | cf2da4689a569c9b436e2f4a1c2c0b2295c821c6 (diff) | |
queryset-refactor: Second part of select_related() fix.
Relations on the parent model can now be specified as part of the fields list.
Fixed #6761.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 77f3519516..6d36ac3e40 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -769,10 +769,10 @@ class Query(object): return if not opts: opts = self.get_meta() - root_alias = self.tables[0] + root_alias = self.get_initial_alias() self.select.extend(self.get_default_columns()) if not used: - used = [] + used = set() # Setup for the case when only particular related fields should be # included in the related selection. @@ -783,14 +783,24 @@ class Query(object): else: restricted = False - for f in opts.fields: + for f, model in opts.get_fields_with_model(): if (not f.rel or (restricted and f.name not in requested) or (not restricted and f.null) or f.rel.parent_link): continue table = f.rel.to._meta.db_table - alias = self.join((root_alias, table, f.column, + if model: + int_opts = opts + alias = root_alias + for int_model in opts.get_base_chain(model): + 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) + else: + alias = root_alias + alias = self.join((alias, table, f.column, f.rel.get_related_field().column), exclusions=used) - used.append(alias) + used.add(alias) self.select.extend([(alias, f2.column) for f2 in f.rel.to._meta.fields]) if restricted: |
