I have two tables Materials and MaterialSubFamilies which are defined like this:
class MaterialSubFamilies(db.Model):
sub_family = db.Column(db.String(64), index=True)
materials = db.relationship('Materials', backref='msub_family', lazy='dynamic')
class Materials(db.Model):
sub_family = db.Column(db.Integer, db.ForeignKey('material_sub_families.id'))
After I query the Materials table I convert it to dict using Marshmallow using this schema:
class MaterialsSchema(ma.ModelSchema):
class Meta:
model = models.Materials
And what I get is something like this:
"materials": [
{"id": 1,
"name": "bla",
"msub_family": 2,
}]
However what I would like is to have not the id of the SubFamily but it's name directly (the string in the sub_family field) when I get the Materials dictionary. So it's a sort of join that I want to have automatically every time I query the Materials table. Is something like this possible ? Thanks