]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
get __clause_element__ for remote()/foreign() annotation, [ticket:2493]
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 24 May 2012 15:12:39 +0000 (11:12 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 24 May 2012 15:12:39 +0000 (11:12 -0400)
lib/sqlalchemy/orm/relationships.py
test/ext/test_declarative.py

index 55c5071df11bb672e44c2eeb018cadf46707084b..0fcf04e6e6d1edb5609483e7cb6d7554c5f07511 100644 (file)
@@ -66,7 +66,7 @@ def remote(expr):
     * :func:`.remote_foreign`
     
     """
-    return _annotate_columns(expr, {"remote":True})
+    return _annotate_columns(expression._clause_element_as_expr(expr), {"remote":True})
 
 def foreign(expr):
     """Annotate a portion of a primaryjoin expression 
@@ -78,7 +78,7 @@ def foreign(expr):
 
     """
 
-    return _annotate_columns(expr, {"foreign":True})
+    return _annotate_columns(expression._clause_element_as_expr(expr), {"foreign":True})
 
 def remote_foreign(expr):
     """Annotate a portion of a primaryjoin expression 
index 1d9f7f39bdbe1eb78fd61e740e999c46005801ae..36cd598abb54ae8981e600ffe84c6799b4ae5675 100644 (file)
@@ -266,6 +266,29 @@ class DeclarativeTest(DeclarativeTestBase):
                               "does not have a mapped column named "
                               "'__table__'", configure_mappers)
 
+    def test_string_w_pj_annotations(self):
+
+        class User(Base, fixtures.ComparableEntity):
+            __tablename__ = 'users'
+            id = Column(Integer, primary_key=True,
+                        test_needs_autoincrement=True)
+            name = Column(String(50))
+        class Address(Base, fixtures.ComparableEntity):
+
+            __tablename__ = 'addresses'
+            id = Column(Integer, primary_key=True,
+                        test_needs_autoincrement=True)
+            email = Column(String(50))
+            user_id = Column(Integer) 
+            user = relationship("User", 
+                primaryjoin="remote(User.id)==foreign(Address.user_id)"
+            )
+
+        eq_(
+            Address.user.property._join_condition.local_remote_pairs,
+            [(Address.__table__.c.user_id, User.__table__.c.id)]
+        )
+
     def test_string_dependency_resolution_no_magic(self):
         """test that full tinkery expressions work as written"""