don't generate relationships for joined subclass to superclass / automap

Issue #3004 resolved
Mike Bayer repo owner created an issue
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.automap import automap_base

Base = automap_base(declarative_base=declarative_base())

class Employee(Base):
    __tablename__ = 'employee'
    id = Column(Integer, primary_key=True)
    name = Column(String(50))
    type = Column(String(50))
    __mapper_args__ = {
        'polymorphic_identity':'employee', 'polymorphic_on':type
    }

class Engineer(Employee):
    __tablename__ = 'engineer'
    id = Column(Integer, ForeignKey('employee.id'), primary_key=True)
    engineer_name = Column(String(30))
    __mapper_args__ = {
        'polymorphic_identity':'engineer',
    }


engine = create_engine("sqlite://")
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)

Base.prepare(engine, reflect=True)
assert not Engineer.__mapper__.relationships

Comments (1)

  1. Mike Bayer reporter
    • Added support to automap for the case where a relationship should not be created between two classes that are in a joined inheritance relationship, for those foreign keys that link the subclass back to the superclass. fixes #3004

    → <<cset 4d93a52e7789>>

  2. Log in to comment