MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / selectinload

Method selectinload

lib/sqlalchemy/orm/strategy_options.py:358–418  ·  view source on GitHub ↗

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

(
        self,
        attr: _AttrType,
        recursion_depth: Optional[int] = None,
        chunksize: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

356 return self._set_relationship_strategy(attr, {"lazy": "subquery"})
357
358 def selectinload(
359 self,
360 attr: _AttrType,
361 recursion_depth: Optional[int] = None,
362 chunksize: Optional[int] = None,
363 ) -> Self:
364 """Indicate that the given attribute should be loaded using
365 SELECT IN eager loading.
366
367 This function is part of the :class:`_orm.Load` interface and supports
368 both method-chained and standalone operation.
369
370 examples::
371
372 # selectin-load the "orders" collection on "User"
373 select(User).options(selectinload(User.orders))
374
375 # selectin-load Order.items and then Item.keywords
376 select(Order).options(
377 selectinload(Order.items).selectinload(Item.keywords)
378 )
379
380 # lazily load Order.items, but when Items are loaded,
381 # selectin-load the keywords collection
382 select(Order).options(lazyload(Order.items).selectinload(Item.keywords))
383
384 :param recursion_depth: optional int; when set to a positive integer
385 in conjunction with a self-referential relationship,
386 indicates "selectin" loading will continue that many levels deep
387 automatically until no items are found.
388
389 .. note:: The :paramref:`_orm.selectinload.recursion_depth` option
390 currently supports only self-referential relationships. There
391 is not yet an option to automatically traverse recursive structures
392 with more than one relationship involved.
393
394 Additionally, the :paramref:`_orm.selectinload.recursion_depth`
395 parameter is new and experimental and should be treated as "alpha"
396 status for the 2.0 series.
397
398 .. versionadded:: 2.0 added
399 :paramref:`_orm.selectinload.recursion_depth`
400
401 :param chunksize: optional int; when set to a positive non-zero
402 integer, the keys from the IN statement will be chunked relative
403 to the passed parameter
404
405 .. versionadded:: 2.1.0b3
406
407 .. seealso::
408
409 :ref:`loading_toplevel`
410
411 :ref:`selectin_eager_loading`
412
413 """
414 return self._set_relationship_strategy(
415 attr,

Calls 1