This is my base class
class Product(Base):
__tablename__ = 'PRODUCT'
__table_args__ = {'quote':False}
...
id = Column(Integer, name='id_prod', primary_key=True)
type = Column(String(100),name='id_typ_prod')
__mapper_args__ = {'polymorphic_on': type}
So, naturally we have a number of classes that extends from this Product, e.g. Phone and Cable, each of them maps to its own table.
class Phone (Product):
__tablename__ = 'PHONE'
...
Now for some reasons now I want to create a ‘alias’ class, a class that does not have a corresponding table in database. Something like this:
class VapourWare(Product):
...
If I do
class VapourWare(Product):
__tablename__ = 'PRODUCT'
__mapper_args__ = {'polymorphic_identity':'VapourWare'}
It seems to work. But is it the right or recommended way? I am repeating __tablename__ = 'PRODUCT' here.
To some degree it depends on what you’re trying to achieve, but from your example it seems that what you’re trying to do is called Single-Table Inheritence in the SA Docs. The example listed on the linked page seems very much like your example, with
Employee == ProductandManager == VapourWare(insert Dilbert joke here).