Hi,

I wish to have a two-levels inheritance, but I don't know how to proceed.
The docs says that "only one discriminator column or SQL expression may be 
configured for the entire inheritance hierarchy".

I tried with this example (mixing joined and single inheritances) :

class Person(Base):
    __tablename__ = 'person'

    id = Column(Integer, primary_key=True)
    type = Column(String(50), nullable=False)
    name = Column(String(50))

    __mapper_args__ = {
        'polymorphic_identity': 'person',
        'polymorphic_on': type
    }

class Manager(Person):
    __tablename__ = 'manager'

    id = Column(ForeignKey('person.id'), primary_key=True)
    manager_name = Column(String(30))

    __mapper_args__ = {
        'polymorphic_identity': 'manager',
    }

class EngineerBase(Person):
    __tablename__ = 'engineer'

    id = Column(ForeignKey('person.id'), primary_key=True)
    engineer_name = Column(String(30))

class EngineerType1(EngineerBase):

    __mapper_args__ = {
        'polymorphic_identity': 'engineer_t1',
    }

class EngineerType2(EngineerBase):

    __mapper_args__ = {
        'polymorphic_identity': 'engineer_t2',
    }

It seems to work, but it this correct ?

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to