Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les fondamentaux
Voir le programme détaillé
Module « sqlalchemy.orm »

Fonction load_only - module sqlalchemy.orm

Signature de la fonction load_only

def load_only(*attrs: '_AttrType', raiseload: 'bool' = False) -> '_AbstractLoad' 

Description

help(sqlalchemy.orm.load_only)

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.

Example - given a class ``User``, load only the ``name`` and
``fullname`` attributes::

    session.query(User).options(load_only(User.name, User.fullname))

Example - given a relationship ``User.addresses -> Address``, specify
subquery loading for the ``User.addresses`` collection, but on each
``Address`` object load only the ``email_address`` attribute::

    session.query(User).options(
        subqueryload(User.addresses).load_only(Address.email_address)
    )

For a statement that has multiple entities,
the lead entity can be
specifically referred to using the :class:`_orm.Load` constructor::

    stmt = (
        select(User, Address)
        .join(User.addresses)
        .options(
            Load(User).load_only(User.name, User.fullname),
            Load(Address).load_only(Address.email_address),
        )
    )

When used together with the
:ref:`populate_existing <orm_queryguide_populate_existing>`
execution option only the attributes listed will be refreshed.

:param \*attrs: Attributes to be loaded, all others will be deferred.

:param raiseload: raise :class:`.InvalidRequestError` rather than
 lazy loading a value when a deferred attribute is accessed. Used
 to prevent unwanted SQL from being emitted.

 .. versionadded:: 2.0

.. seealso::

    :ref:`orm_queryguide_column_deferral` - in the
    :ref:`queryguide_toplevel`

:param \*attrs: Attributes to be loaded, all others will be deferred.

:param raiseload: raise :class:`.InvalidRequestError` rather than
 lazy loading a value when a deferred attribute is accessed. Used
 to prevent unwanted SQL from being emitted.

 .. versionadded:: 2.0



Vous êtes un professionnel et vous avez besoin d'une formation ? Machine Learning
avec Scikit-Learn
Voir le programme détaillé