biosustain / potion

Flask-Potion is a RESTful API framework for Flask and SQLAlchemy, Peewee or MongoEngine
http://potion.readthedocs.io
Other
487 stars 51 forks source link

Expose query.options to SQLAlchemyManager from the Resource #168

Closed ticosax closed 5 years ago

ticosax commented 5 years ago

Useful to perform some prefetching of your relations in order to avoid the n+1 queries problem.

class TypeResource(ModelResource):
    class Meta:
        model = Type
        include_type = True
        query_options = [joinedload(Type.machines)]

    class Schema:
        machines = fields.ToMany('machine')
coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.02%) to 89.095% when pulling 961d2f6422519d6effd5121ec676a3ec222a0dfb on ticosax:query-options into 1ae0208d941a3a76855ac67369ed5031dcc6f636 on biosustain:master.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.02%) to 89.131% when pulling 961d2f6422519d6effd5121ec676a3ec222a0dfb on ticosax:query-options into 1ae0208d941a3a76855ac67369ed5031dcc6f636 on biosustain:master.

lyschoening commented 5 years ago

Thanks for this contribution!