I am using sqlalchemy and marshmallow in my RESTful flask application to serialize my models. I have a hybrid_property that comes from one of my relationships on that model. I would like to now serialize that hybrid_property in my schema using the schema from the related model.
Has anyone done this before? Here are my relevant pieces of code. It doesn't seem to be including the last_assessment in the serialized version of the model when I check the response
class Person(db.Model):
daily_rula_average_ranges = db.relationship('DailyRulaAverageRange', order_by="DailyRulaAverageRange.date", back_populates='person')
@hybrid_property
def last_assessment(self):
if self.daily_rula_average_ranges.length > 0:
return self.daily_rula_average_ranges[-1]
class PersonSchema(ma.Schema):
last_assessment = ma.Nested(DailyRulaAverageRangeSchema, only=['id', 'date', 'risk'])
class Meta:
fields = ('last_assessment')
@propertydecorator on top of the hybrid_property one? - Charles David