Commits

Mike Bayer committed 5edc86c

- Fixed exception throw which would occur when string-based
primaryjoin condition was used in conjunction with backref.

  • Participants
  • Parent commits c46ee38

Comments (0)

Files changed (3)

       by the ORM.
 
     - Session.delete() adds the given object to the session if 
-      not already present.  This was a regression bug from 0.4
+      not already present.  This was a regression bug from 0.4.
       [ticket:1150]
       
     - The `echo_uow` flag on `Session` is deprecated, and unit-of-work
 - declarative
     - Fixed bug whereby mapper couldn't initialize if a composite
       primary key referenced another table that was not defined
-      yet [ticket:1161]
+      yet. [ticket:1161]
+    
+    - Fixed exception throw which would occur when string-based
+      primaryjoin condition was used in conjunction with backref.
       
 - schema
     - Added "sorted_tables" accessor to MetaData, which returns

File lib/sqlalchemy/ext/declarative.py

             if isinstance(v, basestring):
                 setattr(prop, attr, resolve_arg(v))
 
+        if prop.backref:
+            for attr in ('primaryjoin', 'secondaryjoin'):
+               if attr in prop.backref.kwargs and isinstance(prop.backref.kwargs[attr], basestring):
+                   prop.backref.kwargs[attr] = resolve_arg(prop.backref.kwargs[attr])
+
+
     return prop
 
 def synonym_for(name, map_column=False):

File test/ext/declarative.py

 from sqlalchemy import exc
 from testlib import sa, testing
 from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, ForeignKeyConstraint, asc
-from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers
+from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref
 from testlib.testing import eq_
 from orm._base import ComparableEntity
 
             id = Column(Integer, primary_key=True)
             rel = relation("User", primaryjoin="User.addresses==Foo.id")
         self.assertRaisesMessage(exc.InvalidRequestError, "'addresses' is not an instance of ColumnProperty", compile_mappers)
-    
+
+    def test_string_dependency_resolution_in_backref(self):
+        class User(Base, ComparableEntity):
+            __tablename__ = 'users'
+            id = Column(Integer, primary_key=True)
+            name = Column(String(50))
+            addresses = relation("Address", 
+                primaryjoin="User.id==Address.user_id", 
+                backref="user"
+                )
+
+        class Address(Base, ComparableEntity):
+            __tablename__ = 'addresses'
+            id = Column(Integer, primary_key=True)
+            email = Column(String(50))
+            user_id = Column(Integer, ForeignKey('users.id'))  
+
+        compile_mappers()
+        eq_(str(User.addresses.property.primaryjoin), str(Address.user.property.primaryjoin))
+        
+        
     def test_uncompiled_attributes_in_relation(self):
         class Address(Base, ComparableEntity):
             __tablename__ = 'addresses'