Flask-SQLAlchemy and Flask-Restless not fetching grandchildren Flask-SQLAlchemy and Flask-Restless not fetching grandchildren flask flask

Flask-SQLAlchemy and Flask-Restless not fetching grandchildren


postprocessors can be used to fetch grandchild.

def parent_post_get_many(result=None, search_params=None, **kw):   for object in result['objects']:      for child in object['children']:         grandchild = Grandchild.query.get(child['grand_child_id'])         child.update({'grandchild': grandchild})api.create_api(Parent, postprocessors={'GET_MANY': [parent_post_get_many]})


After looking at this for a few hours I'm going to give the best answer I have at the moment. I've tried a number of approaches and haven't been able to get anything to successfully render the grandchild, so I turned to the flask-restless issues tracker to see what I could find:

https://github.com/jfinkels/flask-restless/pull/222#issuecomment-31326359 and @jfinkels response seem to indicate that what you want is currently not possible in flask-restless.

Assuming my assessment of the state of issues is correct, you may want to look into either designing around this issue, or using a different package to serve your API (perhaps Flask-restful, though I admit I haven't used it and don't know if it's suitable).

FWIW, I've been using Flask-Classy to build a json API for a project I'm working on. The process is a little more involved than I suspect you want, but it also comes with enough freedom to better control what queries are used and how the results are serialized.