I need to have 2 separate tables with identical structures which seems like an inheritance scenario, but I don't want the base class to be associated with a table. The Base only exists to define the columns for the table(s) in the child class(es). The AbstractConcreteBase docs led me to implement it this way:
in status.py:
class Base(AbstractConcreteBase):
id = Column('id', Integer, primary_key=True)
date = Column('date', DateTime(), nullable=False)
class Status1(Base):
__tablename__ = 'status1'
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'concrete': True
}
class Status2(Base):
__tablename__ = 'status2'
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'concrete': True
}
in part.py:
class Part(declarative_base()):
__tablename__ = 'parts'
id = Column('id', Integer, primary_key=True)
status1 = relationship('Status1', uselist=True, backref=backref('status1', order_by='Status1.date'))
status2 = relationship('Status2', uselist=True, backref=backref('status2', order_by='Status2.date'))
When attempting this, I get the following error:
InvalidRequestError: When initializing mapper Mapper|Part|parts, expression 'Status1' failed to locate a name ("name 'Status1' is not defined"). If this is a class name, consider adding this relationship() to the <class 'package.Part'> class after both dependent classes have been defined.
Suggestions?