擅长:python、mysql、java
<p>要强制所有内容延迟加载,忽略在关系上指定的内容,可以使用<code>'*'</code>目标。来自<a href="http://docs.sqlalchemy.org/en/latest/orm/loading.html#default-loading-strategies" rel="nofollow">the docs</a>:</p>
<blockquote>
<p>affecting all relationships not otherwise specified in the query. This
feature is available by passing the string <code>'*'</code> as the argument to any
of these options:</p>
<pre><code>session.query(Article).options(lazyload('*'))
</code></pre>
</blockquote>
<p>然后,可以为每个关系或关系链指定所需的任何负载类型。在</p>
<pre><code># not sure how you are mapping json data to relationships
# once you know the relationships, you can build a list of them to load
my_loads = [joinedload(rel) for rel in json_rel_data]
query = session.query(Article).options(lazyload('*'), *my_loads)
# query lazy loads **everything** except the explicitly set joined loads
</code></pre>
<p>如果出于查询目的而加入关系,则可以在选项中使用<code>contains_eager</code>而不是{<cd3>}来使用已经联接的关系。在</p>
^{pr2}$