From 779068fb41a216f65f6cd18d50b261e378ed67ac Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 17 May 2007 15:11:34 +0000 Subject: - fix to select_by(=) -style joins in conjunction with many-to-many relationships, bug introduced in r2556 - the "reverse_direction" flag in _create_lazy_clause works correctly for a many-to-many relationship (i.e. the reverse is on which clause, not which column in the clause, in the case of m2m) --- lib/sqlalchemy/orm/properties.py | 2 ++ lib/sqlalchemy/orm/strategies.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 171021da8..6677e4ab9 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -418,6 +418,8 @@ class PropertyLoader(StrategizedProperty): if logging.is_info_enabled(self.logger): self.logger.info(str(self) + " setup primary join " + str(self.primaryjoin)) self.logger.info(str(self) + " setup polymorphic primary join " + str(self.polymorphic_primaryjoin)) + self.logger.info(str(self) + " setup secondary join " + str(self.secondaryjoin)) + self.logger.info(str(self) + " setup polymorphic secondary join " + str(self.polymorphic_secondaryjoin)) self.logger.info(str(self) + " foreign keys " + str([str(c) for c in self.foreign_keys])) self.logger.info(str(self) + " remote columns " + str([str(c) for c in self.remote_side])) self.logger.info(str(self) + " relation direction " + (self.direction is sync.ONETOMANY and "one-to-many" or (self.direction is sync.MANYTOONE and "many-to-one" or "many-to-many"))) diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 033d0cac1..f1b159318 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -253,7 +253,7 @@ class LazyLoader(AbstractRelationLoader): reverse = {} def should_bind(targetcol, othercol): - if reverse_direction: + if reverse_direction and not secondaryjoin: return targetcol in remote_side else: return othercol in remote_side @@ -293,10 +293,14 @@ class LazyLoader(AbstractRelationLoader): lazywhere = primaryjoin.copy_container() li = mapperutil.BinaryVisitor(visit_binary) - li.traverse(lazywhere) + + if not secondaryjoin or not reverse_direction: + li.traverse(lazywhere) if secondaryjoin is not None: secondaryjoin = secondaryjoin.copy_container() + if reverse_direction: + li.traverse(secondaryjoin) lazywhere = sql.and_(lazywhere, secondaryjoin) if hasattr(cls, 'parent_property'): -- cgit v1.2.1