Flask-sqlalchemy Single Table Inheritance
SQLAlchemy support single table inheritance. I have structure like: class User(db.Model): __tablename__ = 'tbl_user' type = db.Column(db.String(32)) ... __mapper_a
Solution 1:
I've finally found a way how mentioned should work. I need to remove with_polymorfic
option from initial mapper args and to add __tablename__ = None
for children classes, so exact code look like:
class User(db.Model):
__tablename__ = 'tbl_user'
type = db.Column(db.String(32))
...
__mapper_args__ = {
'polymorphic_identity': 'user',
'polymorphic_on': type,
} # remove with_polymorphic
class Tourist(User):
__tablename__ = None # Add table name to be None
__mapper_args__ = {
'polymorphic_identity': 'tourist'
}
...
class Guide(User):
__tablename__ = None # Add table name to be None
__mapper_args__ = {
'polymorphic_identity': 'guide'
}
...
Post a Comment for "Flask-sqlalchemy Single Table Inheritance"