I have 2 classes. The class SimpleThing
can also contain a list of itself as children.
class SimpleThing():
__tablename__ = 'Simple_Thing'
id = db.Column(db.Integer, primary_key=True, nullable=False)
bundled_things = db.relationship('SimpleThing',
secondary='Bundled_Things',
primaryjoin="SimpleThing.id==Bundled_Thing.c.bundle_id",
secondaryjoin="SimpleThing.id==Bundled_Thing.c.simple_id")
class BundledThing():
__tablename__ = 'Bundled_Thing'
bundle_fkey = db.ForeignKey('Simple_Thing.id')
bundle_id = db.Column(db.Integer, bundle_fkey, nullable=False)
bundle_thing = db.relationship('SimpleThing',
foreign_keys='BundledThing.bundle_id')
simple_fkey = db.ForeignKey('Simple_Thing.id')
simple_id = db.Column(db.Integer, simple_fkey, nullable=False)
simple_thing = db.relationship('SimpleThing',
foreign_keys='BundledThing.simple_id')
quantity = db.Column(db.Integer, nullable=False)
The relationships will populate correctly as a list of the SimpleThing
s but I need the quantity field also. Does anyone know how I can get that to show up as attribute through the relationship? SimpleThing.bundeled_things
are correct, but for each bundeled_thing
I would like to be able to ask for bundled_thing.quantity
populated through the relationship rather than having to query the join table.