]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
removed a "swap" from the lazy binary clause. added a test for that condition....
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Apr 2006 22:11:13 +0000 (22:11 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Apr 2006 22:11:13 +0000 (22:11 +0000)
lib/sqlalchemy/mapping/properties.py
test/lazytest1.py

index 8175ee26414d05b1217952b475ffcd7775816636..c536bbf1365f4673a13b44e97927b4c578d19be6 100644 (file)
@@ -660,7 +660,7 @@ def create_lazy_clause(table, primaryjoin, secondaryjoin, foreignkey):
             binary.left = binds.setdefault(binary.left,
                     sql.BindParamClause(bind_label(), None, shortname = binary.left.name))
             reverselookup[binary.right] = binds[col]
-            binary.swap()
+            #binary.swap()
 
         if isinstance(binary.right, schema.Column) and isinstance(binary.left, schema.Column) and ((not circular and binary.right.table is table) or (circular and binary.left is foreignkey)):
             col = binary.right
@@ -671,7 +671,7 @@ def create_lazy_clause(table, primaryjoin, secondaryjoin, foreignkey):
     lazywhere = primaryjoin.copy_container()
     li = BinaryVisitor(visit_binary)
     lazywhere.accept_visitor(li)
-    #print "PRIMARYJOIN", str(lazywhere), [b.key for b in binds.values()]
+    print "PRIMARYJOIN", str(lazywhere), [b.key for b in binds.values()]
     if secondaryjoin is not None:
         lazywhere = sql.and_(lazywhere, secondaryjoin)
     return (lazywhere, binds, reverselookup)
index a94940816fbef0091c6c1ffff12d7dfb1268bf0e..986f067aab61c21d997f09a207a4108260a6277a 100644 (file)
@@ -56,6 +56,9 @@ class LazyTest(AssertMixin):
         rel_table.drop()
         info_table.drop()
     
+    def setUp(self):
+        clear_mappers()
+        
     def testone(self):
         """tests a lazy load which has multiple join conditions, including two that are against
         the same column in the child table"""
@@ -76,7 +79,8 @@ class LazyTest(AssertMixin):
         Relation.mapper.add_property('datas', relation(Data.mapper,
                primaryjoin=and_(Relation.c.info_pk==Data.c.info_pk,
                Data.c.timeval >= Relation.c.start,
-               Data.c.timeval <= Relation.c.finish),
+               Data.c.timeval <= Relation.c.finish
+            ),
                foreignkey=Data.c.info_pk))
 
         Information.mapper.add_property('rels', relation(Relation.mapper))
@@ -86,6 +90,39 @@ class LazyTest(AssertMixin):
         assert len(info.rels) == 2
         assert len(info.rels[0].datas) == 3
 
+    def testtwo(self):
+        """same thing, but reversing the order of the cols in the join"""
+        class Information(object):
+               pass
+
+        class Relation(object):
+               pass
+
+        class Data(object):
+               pass
+
+        # Create the basic mappers, with no frills or modifications
+        Information.mapper = mapper(Information, info_table)
+        Data.mapper = mapper(Data, data_table)
+        Relation.mapper = mapper(Relation, rel_table)
+
+        Relation.mapper.add_property('datas', relation(Data.mapper,
+               primaryjoin=and_(Relation.c.info_pk==Data.c.info_pk,
+            Relation.c.start <= Data.c.timeval,
+           Relation.c.finish >= Data.c.timeval,
+    #          Data.c.timeval >= Relation.c.start,
+    #          Data.c.timeval <= Relation.c.finish
+            ),
+               foreignkey=Data.c.info_pk))
+
+        Information.mapper.add_property('rels', relation(Relation.mapper))
+
+        info = Information.mapper.get(1)
+        assert info
+        assert len(info.rels) == 2
+        assert len(info.rels[0].datas) == 3
+
+
 if __name__ == "__main__":    
     testbase.main()