From 770ec1ce7aaadffe6a98ddc581d1b05d2657a2e4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 Feb 2006 02:25:42 +0000 Subject: [PATCH] fixed ticket 72, where a copied clause was using the identical bind param object thereby screwing up a generated statement that included both the original clause and the copied clause, when positional parameters were used --- lib/sqlalchemy/sql.py | 2 ++ test/manytomany.py | 61 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 666a9d18cf..f88b3118fb 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -616,6 +616,8 @@ class BindParamClause(ClauseElement, CompareMixin): visitor.visit_bindparam(self) def _get_from_objects(self): return [] + def copy_container(self): + return BindParamClause(self.key, self.value, self.shortname, self.type) def typeprocess(self, value, engine): return self._get_convert_type(engine).convert_bind_param(value, engine) def compare(self, other): diff --git a/test/manytomany.py b/test/manytomany.py index 611ac30c09..4fe5298ca5 100644 --- a/test/manytomany.py +++ b/test/manytomany.py @@ -206,7 +206,66 @@ class M2MTest2(testbase.AssertMixin): del s.courses[1] self.assert_(len(s.courses) == 2) - +class M2MTest3(testbase.AssertMixin): + def setUpAll(self): + e = testbase.db + global c, c2a1, c2a2, b, a + c = Table('c', e, + Column('c1', Integer, primary_key = True), + Column('c2', String(20)), + ).create() + + a = Table('a', e, + Column('a1', Integer, primary_key=True), + Column('a2', String(20)), + Column('c1', Integer, ForeignKey('c.c1')) + ).create() + + c2a1 = Table('ctoaone', e, + Column('c1', Integer, ForeignKey('c.c1')), + Column('a1', Integer, ForeignKey('a.a1')) + ).create() + c2a2 = Table('ctoatwo', e, + Column('c1', Integer, ForeignKey('c.c1')), + Column('a1', Integer, ForeignKey('a.a1')) + ).create() + + b = Table('b', e, + Column('b1', Integer, primary_key=True), + Column('a1', Integer, ForeignKey('a.a1')), + Column('b2', Boolean) + ).create() + + def tearDownAll(self): + b.drop() + c2a2.drop() + c2a1.drop() + a.drop() + c.drop() + + def testbasic(self): + class C(object):pass + class A(object):pass + class B(object):pass + + assign_mapper(B, b) + + assign_mapper(A, a, + properties = { + 'tbs' : relation(B, primaryjoin=and_(b.c.a1==a.c.a1, b.c.b2 == True), lazy=False), + } + ) + + assign_mapper(C, c, + properties = { + 'a1s' : relation(A, secondary=c2a1, lazy=False), + 'a2s' : relation(A, secondary=c2a2, lazy=False) + } + ) + + o1 = C.get(1) + + if __name__ == "__main__": testbase.main() -- 2.47.2