r"""Indicate that for a particular entity, only the given list of column-based attribute names should be loaded; all others will be deferred. This function is part of the :class:`_orm.Load` interface and supports both method-chained and standalone operation.
(self, *attrs: _AttrType, raiseload: bool = False)
| 162 | return cloned |
| 163 | |
| 164 | def load_only(self, *attrs: _AttrType, raiseload: bool = False) -> Self: |
| 165 | r"""Indicate that for a particular entity, only the given list |
| 166 | of column-based attribute names should be loaded; all others will be |
| 167 | deferred. |
| 168 | |
| 169 | This function is part of the :class:`_orm.Load` interface and supports |
| 170 | both method-chained and standalone operation. |
| 171 | |
| 172 | Example - given a class ``User``, load only the ``name`` and |
| 173 | ``fullname`` attributes:: |
| 174 | |
| 175 | session.query(User).options(load_only(User.name, User.fullname)) |
| 176 | |
| 177 | Example - given a relationship ``User.addresses -> Address``, specify |
| 178 | subquery loading for the ``User.addresses`` collection, but on each |
| 179 | ``Address`` object load only the ``email_address`` attribute:: |
| 180 | |
| 181 | session.query(User).options( |
| 182 | subqueryload(User.addresses).load_only(Address.email_address) |
| 183 | ) |
| 184 | |
| 185 | For a statement that has multiple entities, |
| 186 | the lead entity can be |
| 187 | specifically referred to using the :class:`_orm.Load` constructor:: |
| 188 | |
| 189 | stmt = ( |
| 190 | select(User, Address) |
| 191 | .join(User.addresses) |
| 192 | .options( |
| 193 | Load(User).load_only(User.name, User.fullname), |
| 194 | Load(Address).load_only(Address.email_address), |
| 195 | ) |
| 196 | ) |
| 197 | |
| 198 | When used together with the |
| 199 | :ref:`populate_existing <orm_queryguide_populate_existing>` |
| 200 | execution option only the attributes listed will be refreshed. |
| 201 | |
| 202 | :param \*attrs: Attributes to be loaded, all others will be deferred. |
| 203 | |
| 204 | :param raiseload: raise :class:`.InvalidRequestError` rather than |
| 205 | lazy loading a value when a deferred attribute is accessed. Used |
| 206 | to prevent unwanted SQL from being emitted. |
| 207 | |
| 208 | .. versionadded:: 2.0 |
| 209 | |
| 210 | .. seealso:: |
| 211 | |
| 212 | :ref:`orm_queryguide_column_deferral` - in the |
| 213 | :ref:`queryguide_toplevel` |
| 214 | |
| 215 | :param \*attrs: Attributes to be loaded, all others will be deferred. |
| 216 | |
| 217 | :param raiseload: raise :class:`.InvalidRequestError` rather than |
| 218 | lazy loading a value when a deferred attribute is accessed. Used |
| 219 | to prevent unwanted SQL from being emitted. |
| 220 | |
| 221 | .. versionadded:: 2.0 |