From 9ef3cab40b1806d99172e94954976413f860a476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Mon, 17 Dec 2012 00:43:33 +0200 Subject: [PATCH] Made sure join_field is always available in .join() Refs #19385 --- django/db/models/sql/compiler.py | 7 ++++--- django/db/models/sql/query.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index d0e791ba200..b0fb9337051 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -636,10 +636,10 @@ class SQLCompiler(object): int_opts = int_model._meta continue lhs_col = int_opts.parents[int_model].column + link_field = int_opts.get_ancestor_link(int_model) int_opts = int_model._meta alias = self.query.join((alias, int_opts.db_table, lhs_col, - int_opts.pk.column), - promote=promote) + int_opts.pk.column), promote=promote, join_field=link_field) alias_chain.append(alias) else: alias = root_alias @@ -685,10 +685,11 @@ class SQLCompiler(object): int_opts = int_model._meta continue lhs_col = int_opts.parents[int_model].column + link_field = int_opts.get_ancestor_link(int_model) int_opts = int_model._meta alias = self.query.join( (alias, int_opts.db_table, lhs_col, int_opts.pk.column), - promote=True + promote=True, join_field=link_field ) alias_chain.append(alias) alias = self.query.join( diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index c71bc634aa1..841452636bb 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -944,6 +944,7 @@ class Query(object): The 'join_field' is the field we are joining along (if any). """ lhs, table, lhs_col, col = connection + assert lhs is None or join_field is not None existing = self.join_map.get(connection, ()) if reuse is None: reuse = existing @@ -1003,8 +1004,9 @@ class Query(object): for field, model in opts.get_fields_with_model(): if model not in seen: link_field = opts.get_ancestor_link(model) - seen[model] = self.join((root_alias, model._meta.db_table, - link_field.column, model._meta.pk.column)) + seen[model] = self.join( + (root_alias, model._meta.db_table, link_field.column, + model._meta.pk.column), join_field=link_field) self.included_inherited_models = seen def remove_inherited_models(self):