<p dir="auto"><strong>Migrated issue, originally created by jvanasco (<a href="https://github.com/jvanasco">@jvanasco</a>)</strong></p>
<p dir="auto">There doesn't seem to be a (public) way to find out if a path has been registered to a query for eager loading.  (A non-public way seems to be <code class="notranslate">query.__dict__['with_options']</code>)</p>
<p dir="auto">I propose an enhancement to the Query API, which allows a query to be queried for the status of eager loads.</p>
<p dir="auto">In the simplest concept, it would just return a dict where the keys are a stringified path, and the values are the type of load (joinedload vs subqueryload vs contains_eager).  If there is no eager loading for a given relationship, then the key is absent.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="print q.registered_eagers()
&gt; {'foo': 'joinedload', 'foo.bar':' subqueryload', 'foo.biz': 'contains_eager'}"><pre class="notranslate"><code class="notranslate">print q.registered_eagers()
&gt; {'foo': 'joinedload', 'foo.bar':' subqueryload', 'foo.biz': 'contains_eager'}
</code></pre></div>
<p dir="auto">The use-case is when dealing with generative queries that are loading relationships several layers deep; it becomes increasingly hard to ensure you have a load-strategy for each intermediary relationship..</p>
<p dir="auto"><strong>Migrated issue, originally created by Michael Bayer (<a href="https://github.com/zzzeek">@zzzeek</a>)</strong></p>
<p dir="auto">given issues like <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="384632180" data-permission-text="Title is private" data-url="https://github.com/sqlalchemy/sqlalchemy/issues/3223" data-hovercard-type="issue" data-hovercard-url="/sqlalchemy/sqlalchemy/issues/3223/hovercard" href="https://github.com/sqlalchemy/sqlalchemy/issues/3223">#3223</a> and the openstack issues with model_query(), here's a sketch of an idea:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@event.listens_for(EventedQuery, &quot;before_compile&quot;, retval=True)
def append_order_by(new_query):
    
    if inspect(new_query).selects_against(MyClass).has_any():
        for insp in inspect(new_query).selects_against(MyClass).all_aliases():
            new_query = new_query.order_by(insp.entity.whatever)
    return new_query
"><pre class="notranslate"><code class="notranslate">@event.listens_for(EventedQuery, "before_compile", retval=True)
def append_order_by(new_query):
    
    if inspect(new_query).selects_against(MyClass).has_any():
        for insp in inspect(new_query).selects_against(MyClass).all_aliases():
            new_query = new_query.order_by(insp.entity.whatever)
    return new_query

</code></pre></div>
<p dir="auto">with this extension we'd need to identify specific use cases (since we see them all the time anyway) and add them to the docs of this extension as covered use cases.  So the docs here need lots of recipes and they need to be tested.</p>