summaryrefslogtreecommitdiff
path: root/test/orm/inheritance/test_basic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-11-20 16:25:12 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-11-20 16:25:12 -0500
commit3906eed72bb1372e70977092d4900459a97d8e74 (patch)
tree190fe6620522df534bed5fb1e5c9350b2ec2284d /test/orm/inheritance/test_basic.py
parentea55a4644c63358324ce4066c501c048c7a661a6 (diff)
downloadsqlalchemy-3906eed72bb1372e70977092d4900459a97d8e74.tar.gz
- the column assigned to polymorphic_on now behaves like any other
mapped attribute, in that it can be assigned to, mapped to multiple columns. It is also populated immediately upon object construction with its class-based value, so the attribute can be read before any flush occurs. [ticket:1895]
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r--test/orm/inheritance/test_basic.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index 3e4d50d96..896c7618f 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -201,6 +201,75 @@ class PolymorphicSynonymTest(_base.MappedTest):
eq_(sess.query(T2).filter(T2.info=='at2').one(), at2)
eq_(at2.info, "THE INFO IS:at2")
+class PolymorphicAttributeManagementTest(_base.MappedTest):
+ """Test polymorphic_on can be assigned, can be mirrored, etc."""
+
+ run_setup_mappers = 'once'
+
+ @classmethod
+ def define_tables(cls, metadata):
+ Table('table_a', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('class_name', String(50))
+ )
+ Table('table_b', metadata,
+ Column('id', Integer, ForeignKey('table_a.id'), primary_key=True),
+ Column('class_name', String(50))
+ )
+ Table('table_c', metadata,
+ Column('id', Integer, ForeignKey('table_b.id'),primary_key=True)
+ )
+
+ @classmethod
+ @testing.resolve_artifact_names
+ def setup_classes(cls):
+ class A(_base.ComparableEntity):
+ pass
+ class B(A):
+ pass
+ class C(B):
+ pass
+
+ mapper(A, table_a,
+ polymorphic_on=table_a.c.class_name,
+ polymorphic_identity='a')
+ mapper(B, table_b, inherits=A,
+ polymorphic_on=table_b.c.class_name,
+ polymorphic_identity='b')
+ mapper(C, table_c, inherits=B,
+ polymorphic_identity='c')
+
+ @testing.resolve_artifact_names
+ def test_poly_configured_immediate(self):
+ a = A()
+ b = B()
+ c = C()
+ eq_(a.class_name, 'a')
+ eq_(b.class_name, 'b')
+ eq_(c.class_name, 'c')
+
+ @testing.resolve_artifact_names
+ def test_base_class(self):
+ sess = Session()
+ c1 = C()
+ sess.add(c1)
+ sess.commit()
+
+ assert isinstance(sess.query(B).first(), C)
+
+ sess.close()
+
+ assert isinstance(sess.query(A).first(), C)
+
+ @testing.resolve_artifact_names
+ def test_assignment(self):
+ sess = Session()
+ b1 = B()
+ b1.class_name = 'c'
+ sess.add(b1)
+ sess.commit()
+ sess.close()
+ assert isinstance(sess.query(B).first(), C)
class CascadeTest(_base.MappedTest):
"""that cascades on polymorphic relationships continue