summaryrefslogtreecommitdiff
path: root/test/orm/inheritance/test_basic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-02-02 18:10:07 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2011-02-02 18:10:07 -0500
commitc5b4938a9a2918a14397cff3edcee8c69ca249ea (patch)
treed9d4dd5e3d4ad74c2ba271dc36dcc6373854c759 /test/orm/inheritance/test_basic.py
parent5a2c332f5e2faf321a89e93d5d183d7ec3767084 (diff)
downloadsqlalchemy-c5b4938a9a2918a14397cff3edcee8c69ca249ea.tar.gz
- Fixed bug where "middle" class in a polymorphic hierarchy
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]
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r--test/orm/inheritance/test_basic.py45
1 files changed, 44 insertions, 1 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index 7257cbd79..55cc43993 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -1516,6 +1516,50 @@ class PKDiscriminatorTest(_base.MappedTest):
assert a.name=='a1new'
assert p.name=='p1new'
+class NoPolyIdentInMiddleTest(_base.MappedTest):
+ @classmethod
+ def define_tables(cls, metadata):
+ Table('base', metadata,
+ 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):
+ pass
+ class B(A):
+ pass
+ class C(B):
+ pass
+
+ @classmethod
+ @testing.resolve_artifact_names
+ def setup_mappers(cls):
+ mapper(A, base, polymorphic_on=base.c.type)
+ mapper(B, inherits=A)
+ mapper(C, inherits=B, polymorphic_identity='c')
+
+ @testing.resolve_artifact_names
+ def test_load_from_middle(self):
+ s = Session()
+ s.add(C())
+ o = s.query(B).first()
+ eq_(o.type, 'c')
+ assert isinstance(o, C)
+
+ @testing.resolve_artifact_names
+ def test_load_from_base(self):
+ s = Session()
+ s.add(C())
+ o = s.query(A).first()
+ eq_(o.type, 'c')
+ assert isinstance(o, C)
+
+ @testing.resolve_artifact_names
+ def test_discriminator(self):
+ assert class_mapper(B).polymorphic_on is base.c.type
+ assert class_mapper(C).polymorphic_on is base.c.type
class DeleteOrphanTest(_base.MappedTest):
"""Test the fairly obvious, that an error is raised
@@ -1526,7 +1570,6 @@ class DeleteOrphanTest(_base.MappedTest):
"""
-
@classmethod
def define_tables(cls, metadata):
global single, parent