summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-02-02 19:46:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-02-02 19:46:13 -0500
commit9ea19b374630e6ae14cb144942007aa0f8686583 (patch)
tree060ede03d913659925f243c070a0da3fc4fcde9c /lib/sqlalchemy
parent54088c9b33809dd6d76cacfc86f9012d4f61d361 (diff)
downloadsqlalchemy-9ea19b374630e6ae14cb144942007aa0f8686583.tar.gz
- Fixed bug in lazy loading SQL construction whereby a complex
primaryjoin that referred to the same "local" column multiple times in the "column that points to itself" style of self-referential join would not be substituted in all cases. The logic to determine substitutions here has been reworked to be more open-ended. fixes #3300
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/relationships.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py
index df2250a4c..969b231ec 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -2692,27 +2692,31 @@ class JoinCondition(object):
def create_lazy_clause(self, reverse_direction=False):
binds = util.column_dict()
- lookup = collections.defaultdict(list)
equated_columns = util.column_dict()
- if reverse_direction and self.secondaryjoin is None:
- for l, r in self.local_remote_pairs:
- lookup[r].append((r, l))
- equated_columns[l] = r
- else:
- # replace all "local side" columns, which is
- # anything that isn't marked "remote"
+ has_secondary = self.secondaryjoin is not None
+
+ if has_secondary:
+ lookup = collections.defaultdict(list)
for l, r in self.local_remote_pairs:
lookup[l].append((l, r))
equated_columns[r] = l
+ elif not reverse_direction:
+ for l, r in self.local_remote_pairs:
+ equated_columns[r] = l
+ else:
+ for l, r in self.local_remote_pairs:
+ equated_columns[l] = r
def col_to_bind(col):
- if (reverse_direction and col in lookup) or \
- (not reverse_direction and "local" in col._annotations):
- if col in lookup:
- for tobind, equated in lookup[col]:
- if equated in binds:
- return None
+
+ if (
+ (not reverse_direction and 'local' in col._annotations) or
+ reverse_direction and (
+ (has_secondary and col in lookup) or
+ (not has_secondary and 'remote' in col._annotations)
+ )
+ ):
if col not in binds:
binds[col] = sql.bindparam(
None, None, type_=col.type, unique=True)