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