Note that there are some explanatory texts on larger screens.

plurals
  1. POsqlalchemy nested inheritance / polymorphic relationships
    primarykey
    data
    text
    <p>I have a tree that looks like this, reflected via polymorphic inheritance:</p> <pre><code> A / | \ B C D </code></pre> <p>That works great, like:</p> <pre><code>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, } </code></pre> <p>The problem is I need to reflect something more like this:</p> <pre><code> A / | \ B C D / \ E F </code></pre> <p>Where D is not only a polymorphic child of A but also the polymorphic parents of E &amp; F.</p> <p>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.</p> <p>Do I have any options here?</p> <p>EDIT:</p> <p>Just to tie this off, I ended up flattening the tree so it looks like:</p> <pre><code> A / | \ \ B C E F </code></pre> <p>D is now gone and the functionality it provided is in the children (E &amp; F). I'll probably make the common parts a mixin or something.</p> <p>Unfortunate but I couldn't spend more time on this particular issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload