From: Mike Bayer Date: Wed, 12 Mar 2008 21:32:32 +0000 (+0000) Subject: - fixed bug which was preventing synonym() attributes X-Git-Tag: rel_0_4_5~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4003c08832b0227a5a30a3fd06694a6b7f6258f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fixed bug which was preventing synonym() attributes from being used with inheritance --- diff --git a/CHANGES b/CHANGES index d9b9b7d391..732aeaefa4 100644 --- a/CHANGES +++ b/CHANGES @@ -11,7 +11,10 @@ CHANGES - fixed/covered case when using a False value as a polymorphic discriminator - + + - fixed bug which was preventing synonym() attributes + from being used with inheritance + 0.4.4 ------ - sql diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 011dc4d55a..4a8e592cee 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -652,7 +652,7 @@ class Mapper(object): for col in prop.columns: for col in col.proxy_set: self._columntoproperty[col] = prop - elif isinstance(prop, SynonymProperty): + elif isinstance(prop, SynonymProperty) and setparent: prop.instrument = getattr(self.class_, key, None) if isinstance(prop.instrument, Mapper._CompileOnAttr): prop.instrument = object.__getattribute__(prop.instrument, 'existing_prop') diff --git a/test/orm/inheritance/basic.py b/test/orm/inheritance/basic.py index 699d3e7186..9723ac2651 100644 --- a/test/orm/inheritance/basic.py +++ b/test/orm/inheritance/basic.py @@ -80,6 +80,37 @@ class FalseDiscriminatorTest(ORMTest): sess.flush() assert f1.type == 0 +class PolymorphicSynonymTest(ORMTest): + def define_tables(self, metadata): + global t1, t2 + t1 = Table('t1', metadata, Column('id', Integer, primary_key=True), Column('type', Integer, nullable=False), Column('info', Text)) + t2 = Table('t2', metadata, Column('id', Integer, ForeignKey('t1.id'), primary_key=True), Column('data', Integer, nullable=False)) + + def test_polymorphic_synonym(self): + class T1(fixtures.Base): + def info(self): + return "THE INFO IS:" + self._info + def _set_info(self, x): + self._info = x + info = property(info, _set_info) + + class T2(T1):pass + + mapper(T1, t1, polymorphic_on=t1.c.type, polymorphic_identity='t1', properties={ + 'info':synonym('_info', map_column=True) + }) + mapper(T2, t2, inherits=T1, polymorphic_identity='t2') + sess = create_session() + at1 = T1(info='at1') + at2 = T2(info='at2', data='t2 data') + sess.save(at1) + sess.save(at2) + sess.flush() + sess.clear() + self.assertEquals(sess.query(T2).filter(T2.info=='at2').one(), at2) + self.assertEquals(at2.info, "THE INFO IS:at2") + + class CascadeTest(ORMTest): """that cascades on polymorphic relations continue cascading along the path of the instance's mapper, not