]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
custom primary/secondary join conditions in a relation *will* be propigated
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 Jul 2006 04:33:32 +0000 (04:33 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 27 Jul 2006 04:33:32 +0000 (04:33 +0000)
to backrefs by default.  specifying a backref() will override this behavior.

CHANGES
lib/sqlalchemy/orm/properties.py

diff --git a/CHANGES b/CHANGES
index c177757ab96f3acc50e31724e712dfc8e46e07a4..eb8032d9138e39be0ecce4d45f51cdd1eaa3bce9 100644 (file)
--- 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
index 5ff401d275fa3deca4c868a626fc7bf4441a3f8d..2d2bf5fecb66dbe1f0be256a8d1a601d38a63e96 100644 (file)
@@ -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: