need to assign polymorphic_on to all classes in hierarchy

Issue #2038 resolved
Mike Bayer repo owner created an issue

tests which fail:

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

Comments (3)

  1. Log in to comment