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

Method defaultload

lib/sqlalchemy/orm/strategy_options.py:542–579  ·  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

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

Calls 1