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 with_polymorphic - module sqlalchemy.orm

Signature de la fonction with_polymorphic

def with_polymorphic(base: 'Union[Type[_O], Mapper[_O]]', classes: "Union[Literal['*'], Iterable[Type[Any]]]", selectable: 'Union[Literal[False, None], FromClause]' = False, flat: 'bool' = False, polymorphic_on: 'Optional[ColumnElement[Any]]' = None, aliased: 'bool' = False, innerjoin: 'bool' = False, adapt_on_names: 'bool' = False, name: 'Optional[str]' = None, _use_mapper_path: 'bool' = False) -> 'AliasedClass[_O]' 

Description

help(sqlalchemy.orm.with_polymorphic)

Produce an :class:`.AliasedClass` construct which specifies
columns for descendant mappers of the given base.

Using this method will ensure that each descendant mapper's
tables are included in the FROM clause, and will allow filter()
criterion to be used against those tables.  The resulting
instances will also have those columns already loaded so that
no "post fetch" of those columns will be required.

.. seealso::

    :ref:`with_polymorphic` - full discussion of
    :func:`_orm.with_polymorphic`.

:param base: Base class to be aliased.

:param classes: a single class or mapper, or list of
    class/mappers, which inherit from the base class.
    Alternatively, it may also be the string ``'*'``, in which case
    all descending mapped classes will be added to the FROM clause.

:param aliased: when True, the selectable will be aliased.   For a
    JOIN, this means the JOIN will be SELECTed from inside of a subquery
    unless the :paramref:`_orm.with_polymorphic.flat` flag is set to
    True, which is recommended for simpler use cases.

:param flat: Boolean, will be passed through to the
 :meth:`_expression.FromClause.alias` call so that aliases of
 :class:`_expression.Join` objects will alias the individual tables
 inside the join, rather than creating a subquery.  This is generally
 supported by all modern databases with regards to right-nested joins
 and generally produces more efficient queries.  Setting this flag is
 recommended as long as the resulting SQL is functional.

:param selectable: a table or subquery that will
    be used in place of the generated FROM clause. This argument is
    required if any of the desired classes use concrete table
    inheritance, since SQLAlchemy currently cannot generate UNIONs
    among tables automatically. If used, the ``selectable`` argument
    must represent the full set of tables and columns mapped by every
    mapped class. Otherwise, the unaccounted mapped columns will
    result in their table being appended directly to the FROM clause
    which will usually lead to incorrect results.

    When left at its default value of ``False``, the polymorphic
    selectable assigned to the base mapper is used for selecting rows.
    However, it may also be passed as ``None``, which will bypass the
    configured polymorphic selectable and instead construct an ad-hoc
    selectable for the target classes given; for joined table inheritance
    this will be a join that includes all target mappers and their
    subclasses.

:param polymorphic_on: a column to be used as the "discriminator"
    column for the given selectable. If not given, the polymorphic_on
    attribute of the base classes' mapper will be used, if any. This
    is useful for mappings that don't have polymorphic loading
    behavior by default.

:param innerjoin: if True, an INNER JOIN will be used.  This should
   only be specified if querying for one specific subtype only

:param adapt_on_names: Passes through the
  :paramref:`_orm.aliased.adapt_on_names`
  parameter to the aliased object.  This may be useful in situations where
  the given selectable is not directly related to the existing mapped
  selectable.

  .. versionadded:: 1.4.33

:param name: Name given to the generated :class:`.AliasedClass`.

  .. versionadded:: 2.0.31



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé