MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / subqueryload

Method subqueryload

lib/sqlalchemy/orm/strategy_options.py:327–355  ·  view source on GitHub ↗

Indicate that the given attribute should be loaded using subquery eager loading. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. examples:: # subquery-load the "orders" collection on "

(self, attr: _AttrType)

Source from the content-addressed store, hash-verified

325 return loader
326
327 def subqueryload(self, attr: _AttrType) -> Self:
328 """Indicate that the given attribute should be loaded using
329 subquery eager loading.
330
331 This function is part of the :class:`_orm.Load` interface and supports
332 both method-chained and standalone operation.
333
334 examples::
335
336 # subquery-load the "orders" collection on "User"
337 select(User).options(subqueryload(User.orders))
338
339 # subquery-load Order.items and then Item.keywords
340 select(Order).options(
341 subqueryload(Order.items).subqueryload(Item.keywords)
342 )
343
344 # lazily load Order.items, but when Items are loaded,
345 # subquery-load the keywords collection
346 select(Order).options(lazyload(Order.items).subqueryload(Item.keywords))
347
348 .. seealso::
349
350 :ref:`loading_toplevel`
351
352 :ref:`subquery_eager_loading`
353
354 """
355 return self._set_relationship_strategy(attr, {"lazy": "subquery"})
356
357 def selectinload(
358 self,

Calls 1