]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merge trunk fix r6506 for [ticket:1616]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 Nov 2009 20:42:18 +0000 (20:42 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 Nov 2009 20:42:18 +0000 (20:42 +0000)
CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/inheritance/test_basic.py

diff --git a/CHANGES b/CHANGES
index 34b44557942d39b954f0e4adbf225f42fd6ea74a..9bad50eb515e43a207c99cac2fc7557f64cef59f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -36,6 +36,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 714f00f3a817fa84a9bd96d78c4ae20d3bef420c..fd6d3a4a714bc0521257f24987d833dea5b9ca56 100644 (file)
@@ -1172,7 +1172,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 f93dfd5476634441d2fe8191f04b61c48ab8f4c8..6581af1aa18a4736438422c2965ba3c07e1c62e3 100644 (file)
@@ -974,7 +974,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),
             Column('data', String(50)),
@@ -984,6 +984,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 
@@ -1057,6 +1062,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):