How to select_related() in Flask/SQLAlchemy?

最后都变了- 提交于 2019-12-05 11:00:32
answers = Question.query.options(joinedload(Question.answers)).get(5).answers

The expression Question.query.options(joinedload(Question.answers)).get(5) issues the query with a join and evaluates to a Question instance. Accessing answers attribute does not issue any queries.

You could also do it more explicitly

answers = Answer.query.filter_by(question_id=5).all()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!