From 3b41d5c63556179867b297faab05d9ff4e4e46fb Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 27 Jul 2006 04:33:32 +0000 Subject: [PATCH] custom primary/secondary join conditions in a relation *will* be propigated to backrefs by default. specifying a backref() will override this behavior. --- CHANGES | 2 ++ lib/sqlalchemy/orm/properties.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index c177757ab9..eb8032d913 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ primary key columns are null (i.e. when mapping to outer joins etc) if it was not loaded already - [ticket:256] - pass URL query string arguments to connect() function - [ticket:257] - oracle boolean type +- custom primary/secondary join conditions in a relation *will* be propigated +to backrefs by default. specifying a backref() will override this behavior. 0.2.6 - big overhaul to schema to allow truly composite primary and foreign diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 5ff401d275..2d2bf5fecb 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -148,7 +148,13 @@ class PropertyLoader(mapper.MapperProperty): self.order_by = order_by self.attributeext=attributeext if isinstance(backref, str): - self.backref = BackRef(backref) + # propigate explicitly sent primary/secondary join conditions to the BackRef object if + # just a string was sent + if secondary is not None: + # reverse primary/secondary in case of a many-to-many + self.backref = BackRef(backref, primaryjoin=secondaryjoin, secondaryjoin=primaryjoin) + else: + self.backref = BackRef(backref, primaryjoin=primaryjoin, secondaryjoin=secondaryjoin) else: self.backref = backref self.is_backref = is_backref @@ -684,14 +690,15 @@ class BackRef(object): if not mapper.props.has_key(self.key): pj = self.kwargs.pop('primaryjoin', None) sj = self.kwargs.pop('secondaryjoin', None) - # TODO: we are going to have the newly backref'd property create its - # primary/secondary join through normal means, and only override if they are - # specified to the constructor. think about if this is really going to work - # all the way. + # the backref will compile its own primary/secondary join conditions. if you have it + # use the pj/sj of the parent relation in all cases, a bunch of polymorphic unit tests + # fail (maybe we can look into that too). + # the PropertyLoader class is currently constructing BackRef objects using the explictly + # passed primary/secondary join conditions, if the backref was passed to it as just a string. #if pj is None: # if prop.secondaryjoin is not None: - # # if setting up a backref to a many-to-many, reverse the order - # # of the "primary" and "secondary" joins + # if setting up a backref to a many-to-many, reverse the order + # of the "primary" and "secondary" joins # pj = prop.secondaryjoin # sj = prop.primaryjoin # else: -- 2.47.2