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 ? Calcul scientifique
avec Python
Voir le programme détaillé
Module « sqlalchemy.orm »

Fonction with_parent - module sqlalchemy.orm

Signature de la fonction with_parent

def with_parent(instance: 'object', prop: 'attributes.QueryableAttribute[Any]', from_entity: 'Optional[_EntityType[Any]]' = None) -> 'ColumnElement[bool]' 

Description

help(sqlalchemy.orm.with_parent)

Create filtering criterion that relates this query's primary entity
to the given related instance, using established
:func:`_orm.relationship()`
configuration.

E.g.::

    stmt = select(Address).where(with_parent(some_user, User.addresses))

The SQL rendered is the same as that rendered when a lazy loader
would fire off from the given parent on that attribute, meaning
that the appropriate state is taken from the parent object in
Python without the need to render joins to the parent table
in the rendered statement.

The given property may also make use of :meth:`_orm.PropComparator.of_type`
to indicate the left side of the criteria::


    a1 = aliased(Address)
    a2 = aliased(Address)
    stmt = select(a1, a2).where(with_parent(u1, User.addresses.of_type(a2)))

The above use is equivalent to using the
:func:`_orm.with_parent.from_entity` argument::

    a1 = aliased(Address)
    a2 = aliased(Address)
    stmt = select(a1, a2).where(
        with_parent(u1, User.addresses, from_entity=a2)
    )

:param instance:
  An instance which has some :func:`_orm.relationship`.

:param property:
  Class-bound attribute, which indicates
  what relationship from the instance should be used to reconcile the
  parent/child relationship.

:param from_entity:
  Entity in which to consider as the left side.  This defaults to the
  "zero" entity of the :class:`_query.Query` itself.

  .. versionadded:: 1.2



Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé