From 0d90e5cdabecfb02d72acc6598912d1d258bcf51 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 24 Apr 2006 22:11:13 +0000 Subject: [PATCH] removed a "swap" from the lazy binary clause. added a test for that condition.... --- lib/sqlalchemy/mapping/properties.py | 4 +-- test/lazytest1.py | 39 +++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index 8175ee2641..c536bbf136 100644 --- a/lib/sqlalchemy/mapping/properties.py +++ b/lib/sqlalchemy/mapping/properties.py @@ -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) diff --git a/test/lazytest1.py b/test/lazytest1.py index a94940816f..986f067aab 100644 --- a/test/lazytest1.py +++ b/test/lazytest1.py @@ -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() -- 2.47.2