flask-sqlachemy中lazy参数

lazy 的几个参数决定了 SQLAlchemy 什么时候从数据库中加载数据,官网解释如下

  • select: (which is the default) means that SQLAlchemy will load the data as necessary in one go using a standard select statement.
  • joined: tells SQLAlchemy to load the relationship in the same query as the parent using a JOIN statement.
  • subquery: works like ‘joined’ but instead SQLAlchemy will use a subquery.
  • dynamic : is special and useful if you have many items. Instead of loading the items SQLAlchemy will return another query object which you can further refine before loading the items. This is usually what you want if you expect more than a handful of items for this relationship