r"""Indicate that the given column-oriented attribute should be deferred, e.g. not loaded until accessed. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation. e.g.:: from sqlalchemy.orm imp
(self, key: _AttrType, raiseload: bool = False)
| 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 |
| 589 | deferred, e.g. not loaded until accessed. |
| 590 | |
| 591 | This function is part of the :class:`_orm.Load` interface and supports |
| 592 | both method-chained and standalone operation. |
| 593 | |
| 594 | e.g.:: |
| 595 | |
| 596 | from sqlalchemy.orm import defer |
| 597 | |
| 598 | session.query(MyClass).options( |
| 599 | defer(MyClass.attribute_one), defer(MyClass.attribute_two) |
| 600 | ) |
| 601 | |
| 602 | To specify a deferred load of an attribute on a related class, |
| 603 | the path can be specified one token at a time, specifying the loading |
| 604 | style for each link along the chain. To leave the loading style |
| 605 | for a link unchanged, use :func:`_orm.defaultload`:: |
| 606 | |
| 607 | session.query(MyClass).options( |
| 608 | defaultload(MyClass.someattr).defer(RelatedClass.some_column) |
| 609 | ) |
| 610 | |
| 611 | Multiple deferral options related to a relationship can be bundled |
| 612 | at once using :meth:`_orm.Load.options`:: |
| 613 | |
| 614 | |
| 615 | select(MyClass).options( |
| 616 | defaultload(MyClass.someattr).options( |
| 617 | defer(RelatedClass.some_column), |
| 618 | defer(RelatedClass.some_other_column), |
| 619 | defer(RelatedClass.another_column), |
| 620 | ) |
| 621 | ) |
| 622 | |
| 623 | :param key: Attribute to be deferred. |
| 624 | |
| 625 | :param raiseload: raise :class:`.InvalidRequestError` rather than |
| 626 | lazy loading a value when the deferred attribute is accessed. Used |
| 627 | to prevent unwanted SQL from being emitted. |
| 628 | |
| 629 | .. versionadded:: 1.4 |
| 630 | |
| 631 | .. seealso:: |
| 632 | |
| 633 | :ref:`orm_queryguide_column_deferral` - in the |
| 634 | :ref:`queryguide_toplevel` |
| 635 | |
| 636 | :func:`_orm.load_only` |
| 637 | |
| 638 | :func:`_orm.undefer` |
| 639 | |
| 640 | """ |
| 641 | strategy = {"deferred": True, "instrument": True} |
| 642 | if raiseload: |
| 643 | strategy["raiseload"] = True |
| 644 | return self._set_column_strategy( |