]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed bug which was preventing synonym() attributes
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Mar 2008 21:32:32 +0000 (21:32 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Mar 2008 21:32:32 +0000 (21:32 +0000)
from being used with inheritance

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/inheritance/basic.py

diff --git a/CHANGES b/CHANGES
index d9b9b7d39165c506a4dfd20093012a502f25a090..732aeaefa4c724684ac7b82089cba09e84a460d1 100644 (file)
--- 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
index 011dc4d55a96c96fa1b0f6e4ef073a9ecf9171b7..4a8e592ceed8e7e73ec5ecf9bde80f3d135f325a 100644 (file)
@@ -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')
index 699d3e7186fa5d391fc7914645792fa5ee62dc1c..9723ac265172c8e3b3a6f5694a157926977d47ac 100644 (file)
@@ -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