I have a tree that looks like this, reflected via polymorphic inheritance:
A
/ | \
B C D
That works great, like:
class BaseModel(db.Model): # Table A in diagram
__tablename__ = "entities"
id = db.Column(db.BigInteger, primary_key=True, nullable=False, server_default=func.nextval('guid_seq'))
type_id = db.Column(db.SmallInteger, db.ForeignKey(EntityTypesModel.id))
__mapper_args__ = {
'polymorphic_identity':'entity',
'polymorphic_on':type_id,
'with_polymorphic':'*'
}
class BrandModel(BaseModel): # Table B, C, D in diagram
__tablename__ = 'brands'
id = db.Column(db.BigInteger, db.ForeignKey(StufffModel.id), primary_key=True, nullable=False)
name = db.Column(db.String, nullable=False)
__mapper_args__ = {
'polymorphic_identity':ET_BRAND,
}
The problem is I need to reflect something more like this:
A
/ | \
B C D
/ \
E F
Where D is not only a polymorphic child of A but also the polymorphic parents of E & F.
It seems like I have to choose, D can either be a polymorphic child or it can be a parent - it can't be both.
Do I have any options here?
EDIT:
Just to tie this off, I ended up flattening the tree so it looks like:
A
/ | \ \
B C E F
D is now gone and the functionality it provided is in the children (E & F). I'll probably make the common parts a mixin or something.
Unfortunate but I couldn't spend more time on this particular issue.