]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Also emits the correct WHERE criterion
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Feb 2011 00:03:20 +0000 (19:03 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 Feb 2011 00:03:20 +0000 (19:03 -0500)
when using single table inheritance. [ticket:2038]

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

diff --git a/CHANGES b/CHANGES
index 7eca04fa82ab1d504c8c46e4c3bea0894a028b18..7f5ef2f6fdc25d9dbc71b50b1e93e2ece17c39bc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -195,7 +195,8 @@ CHANGES
     would have no 'polymorphic_on' column if it didn't also
     specify a 'polymorphic_identity', leading to strange
     errors upon refresh, wrong class loaded when querying
-    from that target. [ticket:2038]
+    from that target. Also emits the correct WHERE criterion
+    when using single table inheritance. [ticket:2038]
 
 - sql
   - Column.copy(), as used in table.tometadata(), copies the 
index 63d2c4de9471937a4752740130972549427fe026..db445076c888f8e76fba99e35d9ecd20678b30aa 100644 (file)
@@ -983,8 +983,7 @@ class Mapper(object):
     def _single_table_criterion(self):
         if self.single and \
             self.inherits and \
-            self.polymorphic_on is not None and \
-            self.polymorphic_identity is not None:
+            self.polymorphic_on is not None:
             return self.polymorphic_on.in_(
                 m.polymorphic_identity
                 for m in self.self_and_descendants)
index 55cc439935e75465001e186bc401ce9398fca81c..96c31d516f902e27f7f5ef1f4c09bf0b7722395f 100644 (file)
@@ -1520,25 +1520,32 @@ class NoPolyIdentInMiddleTest(_base.MappedTest):
     @classmethod
     def define_tables(cls, metadata):
         Table('base', metadata,
-            Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
+            Column('id', Integer, primary_key=True, 
+                            test_needs_autoincrement=True),
             Column('type', String(50), nullable=False),
         )
 
     @classmethod
     def setup_classes(cls):
-        class A(_base.BasicEntity):
+        class A(_base.ComparableEntity):
             pass
         class B(A):
             pass
         class C(B):
             pass
+        class D(B):
+            pass
+        class E(A):
+            pass
 
     @classmethod
     @testing.resolve_artifact_names
     def setup_mappers(cls):
         mapper(A, base, polymorphic_on=base.c.type)
-        mapper(B, inherits=A)
+        mapper(B, inherits=A)
         mapper(C, inherits=B, polymorphic_identity='c')
+        mapper(D, inherits=B, polymorphic_identity='d')
+        mapper(E, inherits=A, polymorphic_identity='e')
 
     @testing.resolve_artifact_names
     def test_load_from_middle(self):
@@ -1561,6 +1568,15 @@ class NoPolyIdentInMiddleTest(_base.MappedTest):
         assert class_mapper(B).polymorphic_on is base.c.type
         assert class_mapper(C).polymorphic_on is base.c.type
 
+    @testing.resolve_artifact_names
+    def test_load_multiple_from_middle(self):
+        s = Session()
+        s.add_all([C(), D(), E()])
+        eq_(
+            s.query(B).order_by(base.c.type).all(),
+            [C(), D()]
+        )
+
 class DeleteOrphanTest(_base.MappedTest):
     """Test the fairly obvious, that an error is raised
     when attempting to insert an orphan.