MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / defaultload

Method defaultload

lib/sqlalchemy/orm/strategy_options.py:548–585  ·  view source on GitHub ↗

Indicate an attribute should load using its predefined loader style. The behavior of this loading option is to not change the current loading style of the attribute, meaning that the previously configured one is used or, if no previous style was selected, the default

(self, attr: _AttrType)

Source from the content-addressed store, hash-verified

546 )
547
548 def defaultload(self, attr: _AttrType) -> Self:
549 """Indicate an attribute should load using its predefined loader style.
550
551 The behavior of this loading option is to not change the current
552 loading style of the attribute, meaning that the previously configured
553 one is used or, if no previous style was selected, the default
554 loading will be used.
555
556 This method is used to link to other loader options further into
557 a chain of attributes without altering the loader style of the links
558 along the chain. For example, to set joined eager loading for an
559 element of an element::
560
561 session.query(MyClass).options(
562 defaultload(MyClass.someattribute).joinedload(
563 MyOtherClass.someotherattribute
564 )
565 )
566
567 :func:`.defaultload` is also useful for setting column-level options on
568 a related class, namely that of :func:`.defer` and :func:`.undefer`::
569
570 session.scalars(
571 select(MyClass).options(
572 defaultload(MyClass.someattribute)
573 .defer("some_column")
574 .undefer("some_other_column")
575 )
576 )
577
578 .. seealso::
579
580 :ref:`orm_queryguide_relationship_sub_options`
581
582 :meth:`_orm.Load.options`
583
584 """
585 return self._set_relationship_strategy(attr, None)
586
587 def defer(self, key: _AttrType, raiseload: bool = False) -> Self:
588 r"""Indicate that the given column-oriented attribute should be

Callers 1

test_order_byMethod · 0.90

Calls 1