]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug whereby composite columns wouldn't load properly
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 Nov 2009 20:39:39 +0000 (20:39 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 Nov 2009 20:39:39 +0000 (20:39 +0000)
when configured on a joined-table subclass, introduced in
version 0.5.6 as a result of the fix for [ticket:1480].
[ticket:1616] thx to Scott Torborg.

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

diff --git a/CHANGES b/CHANGES
index 917ea9b56fed258b153bcd1b4b57b5c32c28eb99..0e45bf8526a3acfce09092f0c4a059bcfde24de2 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -719,6 +719,11 @@ CHANGES
     - Fixed bug where Query would crash if a join() with no clear
       "left" side were called when a non-mapped column entity
       appeared in the columns list. [ticket:1602]
+    
+    - Fixed bug whereby composite columns wouldn't load properly
+      when configured on a joined-table subclass, introduced in
+      version 0.5.6 as a result of the fix for [ticket:1480].
+      [ticket:1616] thx to Scott Torborg.
       
 - sql
     - Fixed bug in two-phase transaction whereby commit() method
index 146c4d67373bf3f75ec357463f5a9c0f0cf126d7..1c7c37ead7861ca866f213c20f885a8eb071f9da 100644 (file)
@@ -1165,7 +1165,10 @@ class Mapper(object):
 
         cond = sql.and_(*allconds)
 
-        return sql.select([props[key].columns[0] for key in attribute_names], cond, use_labels=True)
+        cols = []
+        for key in attribute_names:
+            cols.extend(props[key].columns)
+        return sql.select(cols, cond, use_labels=True)
 
     def cascade_iterator(self, type_, state, halt_on=None):
         """Iterate each element and its mapper in an object graph,
index a682d38cb1cec5522a6d862b8c41094ce44f1e2a..b02db4e1b3f7d717efa6ad9ce8a40ebbe7851e98 100644 (file)
@@ -1021,7 +1021,7 @@ class OptimizedLoadTest(_base.MappedTest):
     
     @classmethod
     def define_tables(cls, metadata):
-        global base, sub
+        global base, sub, with_comp
         base = Table('base', metadata,
             Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
             Column('data', String(50)),
@@ -1031,6 +1031,11 @@ class OptimizedLoadTest(_base.MappedTest):
             Column('id', Integer, ForeignKey('base.id'), primary_key=True),
             Column('sub', String(50))
         )
+        with_comp = Table('with_comp', metadata,
+            Column('id', Integer, ForeignKey('base.id'), primary_key=True),
+            Column('a', String(10)),
+            Column('b', String(10))
+        )
     
     def test_optimized_passes(self):
         """"test that the 'optimized load' routine doesn't crash when 
@@ -1104,6 +1109,35 @@ class OptimizedLoadTest(_base.MappedTest):
                 Sub(data='s3data', sub='s3sub', concat='s3data|s3sub')
             ]
         )
+
+    def test_composite_column_joined(self):
+        class Base(_base.ComparableEntity):
+            pass
+        class WithComp(Base):
+            pass
+        class Comp(object):
+            def __init__(self, a, b):
+                self.a = a
+                self.b = b
+            def __composite_values__(self):
+                return self.a, self.b
+            def __eq__(self, other):
+                return (self.a == other.a) and (self.b == other.b)
+        mapper(Base, base, polymorphic_on=base.c.type, polymorphic_identity='base')
+        mapper(WithComp, with_comp, inherits=Base, polymorphic_identity='wc', properties={
+            'comp': composite(Comp, with_comp.c.a, with_comp.c.b)
+        })
+        sess = sessionmaker()()
+        s1 = WithComp(data='s1data', comp=Comp('ham', 'cheese'))
+        s2 = WithComp(data='s2data', comp=Comp('bacon', 'eggs'))
+        sess.add_all([s1, s2])
+        sess.commit()
+        sess.expunge_all()
+        s1test, s2test = sess.query(Base).order_by(Base.id).all()
+        assert s1test.comp
+        assert s2test.comp
+        eq_(s1test.comp, Comp('ham', 'cheese'))
+        eq_(s2test.comp, Comp('bacon', 'eggs'))
         
         
 class PKDiscriminatorTest(_base.MappedTest):