How to load nested relationships in SQLAlchemy?
The subqueryload_all
function is deprecated since version 0.9.
Use method chaining with subqueryload
instead:
from sqlalchemy.orm import subqueryload
session.query(MyClass).options(
subqueryload("someattribute").subqueryload("anotherattribute")
)
Changing the subqueryload_all(...)
part of your query to one of the two following options will do the job:
# option-1:
subqueryload_all(
'orders.details', # @note: this will load both *orders* and their *details*
)
# option-2:
subqueryload_all(
Purchase.orders, # @note: this will load orders
PurchaseOrder.details, # @note: this will load orders' details
)
Documentation on sqlalchemy.orm.subqueryload_all
is pretty clear on this in the examples listed.