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 :

Module « sqlalchemy.orm »

Fonction load_only - module sqlalchemy.orm

Signature de la fonction load_only

def load_only(*attrs) 

Description

load_only.__doc__

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 :class:`_query.Query` that has multiple entities,
    the lead entity can be
    specifically referred to using the :class:`_orm.Load` constructor::

        session.query(User, Address).join(User.addresses).options(
                    Load(User).load_only(User.name, User.fullname),
                    Load(Address).load_only(Address.email_address)
                )

     .. note:: This method will still load a :class:`_schema.Column` even
        if the column property is defined with ``deferred=True``
        for the :func:`.column_property` function.

    .. versionadded:: 0.9.0