I have looked all over to a solution for this issue and haven't found
a solution. I am trying to use inheritance more than one level deep
and it does not seem to set the discriminator field on the top level
item. It works fine if it is only subclassed once but when you try and
do it twice it fails. The code below shows this happening in as short
of an example as I could come up with.

Thanks in advance for help,

Julian Krause

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey,
create_engine
from sqlalchemy.orm import sessionmaker

Base = declarative_base()

class Person(Base):
    __tablename__ = 'people'
    id = Column(Integer, primary_key=True)
    discriminator = Column('type', String(50))
    __mapper_args__ = {'polymorphic_on': discriminator}

class Engineer(Person):
    __tablename__ = 'engineers'
    id = Column(Integer, ForeignKey('people.id'), primary_key=True)
    primary_language = Column(String(50))
    discriminator = Column('type', String(50))
    __mapper_args__ = {'polymorphic_identity': 'engineer',
'polymorphic_on': discriminator}

class MechanicalEngineer(Engineer):
    __tablename__ = 'mechanical_engineers'
    __mapper_args__ = {'polymorphic_identity': 'mechanical_engineer'}
    id = Column(Integer, ForeignKey('people.id'), primary_key=True)
    engineer_id = Column(Integer, ForeignKey('engineers.id'),
primary_key=True)
    primary_tool = Column(String(50))

engine = create_engine('sqlite:///test.db', echo=True)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)

sess = Session()

me = MechanicalEngineer()
sess.add(me)
sess.commit()

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to