class Mapper(ORMFromClauseRole, ORMEntityColumnsClauseRole[
Defines an association between a Python class and a database table or other relational structure, so that ORM operations against the class may proceed. The :class:`_orm.Mapper` object is instantiated using mapping methods present on the :class:`_orm.registry` object. For information about instantiating new :class:`_orm.Mapper` objects, see :ref:`orm_mapping_classes_toplevel`.
Method | __clause |
Undocumented |
Method | __init__ |
Direct constructor for a new :class:`_orm.Mapper` object. |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | add |
Add the given dictionary of properties to this mapper, using `add_property`. |
Method | add |
Add an individual MapperProperty to this mapper. |
Method | all |
A namespace of all :class:`.InspectionAttr` attributes associated with the mapped class. |
Method | attrs |
A namespace of all :class:`.MapperProperty` objects associated this mapper. |
Method | cascade |
Iterate each element and its mapper in an object graph, for all relationships that meet the given cascade rule. |
Method | column |
Return a namespace of all :class:`.ColumnProperty` properties maintained by this :class:`_orm.Mapper`. |
Method | common |
Return true if the given mapper shares a common inherited parent as this mapper. |
Method | composites |
Return a namespace of all :class:`.Composite` properties maintained by this :class:`_orm.Mapper`. |
Method | get |
return a MapperProperty associated with the given key. |
Method | get |
Given a :class:`_schema.Column` object, return the :class:`.MapperProperty` which maps this column. |
Method | has |
Undocumented |
Method | identity |
Return the identity key for the given instance, based on its primary key attributes. |
Method | identity |
Return an identity-map key for use in storing/retrieving an item from an identity map. |
Method | identity |
Return an identity-map key for use in storing/retrieving an item from the identity map. |
Method | is |
return true if the other mapper is an inheriting sibling to this one. common parent but different branch |
Method | isa |
Return True if the this mapper inherits from the given mapper. |
Method | iterate |
Undocumented |
Method | polymorphic |
Iterate through the collection including this mapper and all descendant mappers. |
Method | primary |
Return the list of primary key values for the given instance. |
Method | primary |
Return the primary mapper corresponding to this mapper's class key (class). |
Method | relationships |
A namespace of all :class:`.Relationship` properties maintained by this :class:`_orm.Mapper`. |
Method | self |
The collection including this mapper and all descendant mappers. |
Method | synonyms |
Return a namespace of all :class:`.Synonym` properties maintained by this :class:`_orm.Mapper`. |
Class Variable | dispatch |
Undocumented |
Class Variable | is |
Part of the inspection API. |
Class Variable | represents |
Undocumented |
Instance Variable | allow |
Undocumented |
Instance Variable | always |
Undocumented |
Instance Variable | base |
The base-most :class:`_orm.Mapper` in an inheritance chain. |
Instance Variable | batch |
Undocumented |
Instance Variable | c |
A synonym for :attr:`_orm.Mapper.columns`. |
Instance Variable | class_ |
The class to which this :class:`_orm.Mapper` is mapped. |
Instance Variable | class |
The :class:`.ClassManager` which maintains event listeners and class-bound descriptors for this :class:`_orm.Mapper`. |
Instance Variable | column |
Undocumented |
Instance Variable | columns |
A collection of :class:`_schema.Column` or other scalar expression objects maintained by this :class:`_orm.Mapper`. |
Instance Variable | concrete |
Represent ``True`` if this :class:`_orm.Mapper` is a concrete inheritance mapper. |
Instance Variable | configured |
Represent ``True`` if this :class:`_orm.Mapper` has been configured. |
Instance Variable | confirm |
Undocumented |
Instance Variable | eager |
Undocumented |
Instance Variable | exclude |
Undocumented |
Instance Variable | include |
Undocumented |
Instance Variable | inherit |
Undocumented |
Instance Variable | inherit |
Undocumented |
Instance Variable | inherits |
References the :class:`_orm.Mapper` which this :class:`_orm.Mapper` inherits from, if any. |
Instance Variable | legacy |
Undocumented |
Instance Variable | local |
The immediate :class:`_expression.FromClause` which this :class:`_orm.Mapper` refers towards. |
Instance Variable | non |
Represent ``True`` if this :class:`_orm.Mapper` is a "non-primary" mapper, e.g. a mapper that is used only to select rows but not for persistence management. |
Instance Variable | passive |
Undocumented |
Instance Variable | passive |
Undocumented |
Instance Variable | persist |
The :class:`_expression.FromClause` to which this :class:`_orm.Mapper` is mapped. |
Instance Variable | polymorphic |
Undocumented |
Instance Variable | polymorphic |
Represent an identifier which is matched against the :attr:`_orm.Mapper.polymorphic_on` column during result row loading. |
Instance Variable | polymorphic |
Undocumented |
Instance Variable | polymorphic |
A mapping of "polymorphic identity" identifiers mapped to :class:`_orm.Mapper` instances, within an inheritance scenario. |
Instance Variable | polymorphic |
The :class:`_schema.Column` or SQL expression specified as the ``polymorphic_on`` argument for this :class:`_orm.Mapper`, within an inheritance scenario. |
Instance Variable | primary |
An iterable containing the collection of :class:`_schema.Column` objects which comprise the 'primary key' of the mapped table, from the perspective of this :class:`_orm.Mapper`. |
Instance Variable | registry |
Undocumented |
Instance Variable | single |
Represent ``True`` if this :class:`_orm.Mapper` is a single table inheritance mapper. |
Instance Variable | tables |
A sequence containing the collection of :class:`_schema.Table` or :class:`_schema.TableClause` objects which this :class:`_orm.Mapper` is aware of. |
Instance Variable | validators |
An immutable dictionary of attributes which have been decorated using the :func:`_orm.validates` decorator. |
Instance Variable | version |
Undocumented |
Instance Variable | version |
Undocumented |
Instance Variable | version |
Undocumented |
Instance Variable | with |
Undocumented |
Property | entity |
Part of the inspection API. |
Property | entity |
Undocumented |
Property | iterate |
return an iterator of all MapperProperty objects. |
Property | mapped |
Undocumented |
Property | mapper |
Part of the inspection API. |
Property | primary |
Undocumented |
Property | select |
Undocumented |
Property | selectable |
The :class:`_schema.FromClause` construct this :class:`_orm.Mapper` selects from by default. |
Method | _acceptable |
Undocumented |
Method | _adapt |
Undocumented |
Method | _add |
Undocumented |
Method | _all |
Undocumented |
Method | _canload |
Undocumented |
Method | _check |
Undocumented |
Method | _columns |
Undocumented |
Method | _compiled |
Undocumented |
Method | _configure |
If this mapper is to be a primary mapper (i.e. the non_primary flag is not set), associate this Mapper with the given class and entity name. |
Method | _configure |
Configure settings related to inheriting and/or inherited mappers being present. |
Method | _configure |
Undocumented |
Method | _configure |
Configure an attribute on the mapper representing the 'polymorphic_on' column, if applicable, and not already generated by _configure_properties (which is typical). |
Method | _configure |
Undocumented |
Method | _configure |
Undocumented |
Method | _dataclass |
Undocumented |
Method | _equivalent |
Create a map of all equivalent columns, based on the determination of column pairs that are equated to one another based on inherit condition. This is designed to work with the queries that util.polymorphic_union comes up with, which often don't include the columns from the base table directly (including the subclass table columns only). |
Method | _expire |
Undocumented |
Method | _filter |
Undocumented |
Method | _gen |
return an optional cache key. |
Method | _get |
create a "get clause" based on the primary key. this is used by query.get() and many-to-one lazyloads to load this item by primary key. |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _has |
return True if with_polymorphic[1] is an aliased fromclause, like a subquery. |
Method | _identity |
Undocumented |
Method | _identity |
Undocumented |
Method | _insert |
Undocumented |
Method | _insert |
Undocumented |
Method | _is |
Undocumented |
Method | _is |
Undocumented |
Method | _iterate |
Return an iterator of MapperProperty objects which will render into a SELECT. |
Method | _iterate |
Undocumented |
Method | _log |
Undocumented |
Method | _log |
Undocumented |
Method | _make |
Undocumented |
Method | _mappers |
given a with_polymorphic() argument, return the set of mappers it represents. |
Method | _memo |
Undocumented |
Method | _multiple |
Undocumented |
Method | _optimized |
assemble a WHERE clause which retrieves a given state by primary key, using a minimized set of tables. |
Method | _persistent |
Undocumented |
Method | _pk |
Undocumented |
Method | _pk |
Undocumented |
Method | _pk |
return a dictionary of {syn_attribute_name: pk_attr_name} for all synonyms that refer to primary key columns |
Method | _polymorphic |
Undocumented |
Method | _polymorphic |
Undocumented |
Method | _post |
Call the ``init()`` method on all ``MapperProperties`` attached to this mapper. |
Method | _post |
This hook is invoked by attribute inspection. |
Method | _prefer |
Undocumented |
Method | _primary |
Undocumented |
Method | _prop |
Undocumented |
Method | _property |
generate/update a :class:`.ColumnProperty` given a :class:`_schema.Column` or other SQL expression object. |
Method | _propkey |
Undocumented |
Method | _reconcile |
Undocumented |
Method | _result |
Undocumented |
Method | _selectable |
given a list of mappers (assumed to be within this mapper's inheritance hierarchy), construct an outerjoin amongst those mapper's mapped tables. |
Method | _server |
Undocumented |
Method | _server |
Undocumented |
Method | _server |
Undocumented |
Method | _server |
Undocumented |
Method | _server |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Set the given :class:`_orm.Mapper` as the 'inherits' for this :class:`_orm.Mapper`, assuming this :class:`_orm.Mapper` is concrete and does not already have an inherits. |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _should |
determine whether a particular property should be implicitly present on the class. |
Method | _should |
determine if _MapperEntity or _ORMColumnEntity will need to use polymorphic adaption when setting up a SELECT as well as fetching rows for mapped classes and subclasses against this Mapper. |
Method | _should |
Undocumented |
Method | _should |
Undocumented |
Method | _single |
Undocumented |
Method | _sorted |
Undocumented |
Method | _str |
Undocumented |
Method | _subclass |
Assemble a that can load the columns local to this subclass as a SELECT with IN. |
Method | _subclass |
Undocumented |
Method | _version |
Undocumented |
Method | _version |
Undocumented |
Method | _with |
Undocumented |
Method | _with |
Undocumented |
Method | _with |
Undocumented |
Method | _would |
return True if this mapper would "selectin" polymorphic load based on the given super mapper, and not from a setting from a subclass. |
Method | _would |
Undocumented |
Class Variable | _configure |
Undocumented |
Instance Variable | _all |
Undocumented |
Instance Variable | _clause |
Undocumented |
Instance Variable | _cols |
Undocumented |
Instance Variable | _columntoproperty |
Undocumented |
Instance Variable | _compiled |
Undocumented |
Instance Variable | _delete |
Undocumented |
Instance Variable | _dependency |
Undocumented |
Instance Variable | _dispose |
Undocumented |
Instance Variable | _identity |
Undocumented |
Instance Variable | _inheriting |
Undocumented |
Instance Variable | _inherits |
Undocumented |
Instance Variable | _init |
Undocumented |
Instance Variable | _memoized |
Undocumented |
Instance Variable | _pks |
Undocumented |
Instance Variable | _polymorphic |
Undocumented |
Instance Variable | _primary |
Undocumented |
Instance Variable | _props |
Undocumented |
Instance Variable | _readonly |
Undocumented |
Instance Variable | _ready |
Undocumented |
Instance Variable | _reconstructor |
Undocumented |
Instance Variable | _requires |
Undocumented |
Instance Variable | _set |
Undocumented |
Instance Variable | _sort |
Undocumented |
Instance Variable | _validate |
Undocumented |
Property | _all |
Undocumented |
Property | _log |
Undocumented |
Property | _path |
Undocumented |
Property | _table |
memoized map of tables to collections of columns to be synchronized upwards to the base mapper. |
Inherited from ORMFromClauseRole
:
Class Variable | __slots__ |
Undocumented |
Class Variable | _role |
Undocumented |
Inherited from FromClauseRole
(via ORMFromClauseRole
, StrictFromClauseRole
):
Class Variable | named |
Undocumented |
Class Variable | _is |
Undocumented |
Inherited from ColumnsClauseRole
(via ORMFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ORMEntityColumnsClauseRole
, ORMColumnsClauseRole
):
Property | _select |
Undocumented |
Inherited from AllowsLambdaRole
(via ORMFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ORMEntityColumnsClauseRole
, ORMColumnsClauseRole
, ColumnsClauseRole
, JoinTargetRole
):
Class Variable | allows |
Undocumented |
Inherited from UsesInspection
(via ORMFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ORMEntityColumnsClauseRole
, ORMColumnsClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
):
Class Variable | uses |
Undocumented |
Inherited from MemoizedHasCacheKey
(via ORMFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ORMEntityColumnsClauseRole
, ORMColumnsClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, TypedColumnsClauseRole
):
Method | _generate |
return a cache key. |
Inherited from HasCacheKey
(via ORMFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ORMEntityColumnsClauseRole
, ORMColumnsClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, TypedColumnsClauseRole
, MemoizedHasCacheKey
):
Class Variable | inherit |
Indicate if this :class:`.HasCacheKey` instance should make use of the cache key generation scheme used by its immediate superclass. |
Class Method | _generate |
generate cache key dispatcher for a new class. |
Class Method | _generate |
Undocumented |
Class Variable | _generated |
Undocumented |
Class Variable | _hierarchy |
private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses. |
Class Variable | _is |
Undocumented |
Inherited from Identified
(via ORMFromClauseRole
, StrictFromClauseRole
, FromClauseRole
, ORMEntityColumnsClauseRole
, ORMColumnsClauseRole
, ColumnsClauseRole
, JoinTargetRole
, AllowsLambdaRole
, UsesInspection
, ColumnListRole
, StructuralRole
, TypedColumnsClauseRole
, MemoizedHasCacheKey
, HasCacheKey
):
Class Variable | logger |
Undocumented |
Class Variable | logging |
Undocumented |
Method | _should |
Undocumented |
Method | _should |
Undocumented |
Class Variable | _echo |
Undocumented |
def __init__(self, class_:
Type[ _O]
, local_table: Optional[ FromClause]
= None, properties: Optional[ Mapping[ str, MapperProperty[ Any]]]
= None, primary_key: Optional[ Iterable[ _ORMColumnExprArgument[ Any]]]
= None, non_primary: bool
= False, inherits: Optional[ Union[ Mapper[ Any], Type[ Any]]]
= None, inherit_condition: Optional[ _ColumnExpressionArgument[ bool]]
= None, inherit_foreign_keys: Optional[ Sequence[ _ORMColumnExprArgument[ Any]]]
= None, always_refresh: bool
= False, version_id_col: Optional[ _ORMColumnExprArgument[ Any]]
= None, version_id_generator: Optional[ Union[ Literal[ False], Callable[ [ Any], Any]]]
= None, polymorphic_on: Optional[ Union[ _ORMColumnExprArgument[ Any], str, MapperProperty[ Any]]]
= None, _polymorphic_map: Optional[ Dict[ Any, Mapper[ Any]]]
= None, polymorphic_identity: Optional[ Any]
= None, concrete: bool
= False, with_polymorphic: Optional[ _WithPolymorphicArg]
= None, polymorphic_abstract: bool
= False, polymorphic_load: Optional[ Literal[ 'selectin', 'inline']]
= None, allow_partial_pks: bool
= True, batch: bool
= True, column_prefix: Optional[ str]
= None, include_properties: Optional[ Sequence[ str]]
= None, exclude_properties: Optional[ Sequence[ str]]
= None, passive_updates: bool
= True, passive_deletes: bool
= False, confirm_deleted_rows: bool
= True, eager_defaults: Literal[ True, False, 'auto']
= 'auto', legacy_is_orphan: bool
= False, _compiled_cache_size: int
= 100):
(source)
¶
Direct constructor for a new :class:`_orm.Mapper` object. The :class:`_orm.Mapper` constructor is not called directly, and is normally invoked through the use of the :class:`_orm.registry` object through either the :ref:`Declarative <orm_declarative_mapping>` or :ref:`Imperative <orm_imperative_mapping>` mapping styles. .. versionchanged:: 2.0 The public facing ``mapper()`` function is removed; for a classical mapping configuration, use the :meth:`_orm.registry.map_imperatively` method. Parameters documented below may be passed to either the :meth:`_orm.registry.map_imperatively` method, or may be passed in the ``__mapper_args__`` declarative class attribute described at :ref:`orm_declarative_mapper_options`. :param class\_: The class to be mapped. When using Declarative, this argument is automatically passed as the declared class itself. :param local_table: The :class:`_schema.Table` or other :class:`_sql.FromClause` (i.e. selectable) to which the class is mapped. May be ``None`` if this mapper inherits from another mapper using single-table inheritance. When using Declarative, this argument is automatically passed by the extension, based on what is configured via the :attr:`_orm.DeclarativeBase.__table__` attribute or via the :class:`_schema.Table` produced as a result of the :attr:`_orm.DeclarativeBase.__tablename__` attribute being present. :param polymorphic_abstract: Indicates this class will be mapped in a polymorphic hierarchy, but not directly instantiated. The class is mapped normally, except that it has no requirement for a :paramref:`_orm.Mapper.polymorphic_identity` within an inheritance hierarchy. The class however must be part of a polymorphic inheritance scheme which uses :paramref:`_orm.Mapper.polymorphic_on` at the base. .. versionadded:: 2.0 .. seealso:: :ref:`orm_inheritance_abstract_poly` :param always_refresh: If True, all query operations for this mapped class will overwrite all data within object instances that already exist within the session, erasing any in-memory changes with whatever information was loaded from the database. Usage of this flag is highly discouraged; as an alternative, see the method :meth:`_query.Query.populate_existing`. :param allow_partial_pks: Defaults to True. Indicates that a composite primary key with some NULL values should be considered as possibly existing within the database. This affects whether a mapper will assign an incoming row to an existing identity, as well as if :meth:`.Session.merge` will check the database first for a particular primary key value. A "partial primary key" can occur if one has mapped to an OUTER JOIN, for example. :param batch: Defaults to ``True``, indicating that save operations of multiple entities can be batched together for efficiency. Setting to False indicates that an instance will be fully saved before saving the next instance. This is used in the extremely rare case that a :class:`.MapperEvents` listener requires being called in between individual row persistence operations. :param column_prefix: A string which will be prepended to the mapped attribute name when :class:`_schema.Column` objects are automatically assigned as attributes to the mapped class. Does not affect :class:`.Column` objects that are mapped explicitly in the :paramref:`.Mapper.properties` dictionary. This parameter is typically useful with imperative mappings that keep the :class:`.Table` object separate. Below, assuming the ``user_table`` :class:`.Table` object has columns named ``user_id``, ``user_name``, and ``password``:: class User(Base): __table__ = user_table __mapper_args__ = {'column_prefix':'_'} The above mapping will assign the ``user_id``, ``user_name``, and ``password`` columns to attributes named ``_user_id``, ``_user_name``, and ``_password`` on the mapped ``User`` class. The :paramref:`.Mapper.column_prefix` parameter is uncommon in modern use. For dealing with reflected tables, a more flexible approach to automating a naming scheme is to intercept the :class:`.Column` objects as they are reflected; see the section :ref:`mapper_automated_reflection_schemes` for notes on this usage pattern. :param concrete: If True, indicates this mapper should use concrete table inheritance with its parent mapper. See the section :ref:`concrete_inheritance` for an example. :param confirm_deleted_rows: defaults to True; when a DELETE occurs of one more rows based on specific primary keys, a warning is emitted when the number of rows matched does not equal the number of rows expected. This parameter may be set to False to handle the case where database ON DELETE CASCADE rules may be deleting some of those rows automatically. The warning may be changed to an exception in a future release. .. versionadded:: 0.9.4 - added :paramref:`.mapper.confirm_deleted_rows` as well as conditional matched row checking on delete. :param eager_defaults: if True, the ORM will immediately fetch the value of server-generated default values after an INSERT or UPDATE, rather than leaving them as expired to be fetched on next access. This can be used for event schemes where the server-generated values are needed immediately before the flush completes. The fetch of values occurs either by using ``RETURNING`` inline with the ``INSERT`` or ``UPDATE`` statement, or by adding an additional ``SELECT`` statement subsequent to the ``INSERT`` or ``UPDATE``, if the backend does not support ``RETURNING``. The use of ``RETURNING`` is extremely performant in particular for ``INSERT`` statements where SQLAlchemy can take advantage of :ref:`insertmanyvalues <engine_insertmanyvalues>`, whereas the use of an additional ``SELECT`` is relatively poor performing, adding additional SQL round trips which would be unnecessary if these new attributes are not to be accessed in any case. For this reason, :paramref:`.Mapper.eager_defaults` defaults to the string value ``"auto"``, which indicates that server defaults for INSERT should be fetched using ``RETURNING`` if the backing database supports it and if the dialect in use supports "insertmanyreturning" for an INSERT statement. If the backing database does not support ``RETURNING`` or "insertmanyreturning" is not available, server defaults will not be fetched. .. versionchanged:: 2.0.0rc1 added the "auto" option for :paramref:`.Mapper.eager_defaults` .. seealso:: :ref:`orm_server_defaults` .. versionchanged:: 0.9.0 The ``eager_defaults`` option can now make use of :term:`RETURNING` for backends which support it. .. versionchanged:: 2.0.0 RETURNING now works with multiple rows INSERTed at once using the :ref:`insertmanyvalues <engine_insertmanyvalues>` feature, which among other things allows the :paramref:`.Mapper.eager_defaults` feature to be very performant on supporting backends. :param exclude_properties: A list or set of string column names to be excluded from mapping. .. seealso:: :ref:`include_exclude_cols` :param include_properties: An inclusive list or set of string column names to map. .. seealso:: :ref:`include_exclude_cols` :param inherits: A mapped class or the corresponding :class:`_orm.Mapper` of one indicating a superclass to which this :class:`_orm.Mapper` should *inherit* from. The mapped class here must be a subclass of the other mapper's class. When using Declarative, this argument is passed automatically as a result of the natural class hierarchy of the declared classes. .. seealso:: :ref:`inheritance_toplevel` :param inherit_condition: For joined table inheritance, a SQL expression which will define how the two tables are joined; defaults to a natural join between the two tables. :param inherit_foreign_keys: When ``inherit_condition`` is used and the columns present are missing a :class:`_schema.ForeignKey` configuration, this parameter can be used to specify which columns are "foreign". In most cases can be left as ``None``. :param legacy_is_orphan: Boolean, defaults to ``False``. When ``True``, specifies that "legacy" orphan consideration is to be applied to objects mapped by this mapper, which means that a pending (that is, not persistent) object is auto-expunged from an owning :class:`.Session` only when it is de-associated from *all* parents that specify a ``delete-orphan`` cascade towards this mapper. The new default behavior is that the object is auto-expunged when it is de-associated with *any* of its parents that specify ``delete-orphan`` cascade. This behavior is more consistent with that of a persistent object, and allows behavior to be consistent in more scenarios independently of whether or not an orphan object has been flushed yet or not. See the change note and example at :ref:`legacy_is_orphan_addition` for more detail on this change. :param non_primary: Specify that this :class:`_orm.Mapper` is in addition to the "primary" mapper, that is, the one used for persistence. The :class:`_orm.Mapper` created here may be used for ad-hoc mapping of the class to an alternate selectable, for loading only. .. seealso:: :ref:`relationship_aliased_class` - the new pattern that removes the need for the :paramref:`_orm.Mapper.non_primary` flag. :param passive_deletes: Indicates DELETE behavior of foreign key columns when a joined-table inheritance entity is being deleted. Defaults to ``False`` for a base mapper; for an inheriting mapper, defaults to ``False`` unless the value is set to ``True`` on the superclass mapper. When ``True``, it is assumed that ON DELETE CASCADE is configured on the foreign key relationships that link this mapper's table to its superclass table, so that when the unit of work attempts to delete the entity, it need only emit a DELETE statement for the superclass table, and not this table. When ``False``, a DELETE statement is emitted for this mapper's table individually. If the primary key attributes local to this table are unloaded, then a SELECT must be emitted in order to validate these attributes; note that the primary key columns of a joined-table subclass are not part of the "primary key" of the object as a whole. Note that a value of ``True`` is **always** forced onto the subclass mappers; that is, it's not possible for a superclass to specify passive_deletes without this taking effect for all subclass mappers. .. versionadded:: 1.1 .. seealso:: :ref:`passive_deletes` - description of similar feature as used with :func:`_orm.relationship` :paramref:`.mapper.passive_updates` - supporting ON UPDATE CASCADE for joined-table inheritance mappers :param passive_updates: Indicates UPDATE behavior of foreign key columns when a primary key column changes on a joined-table inheritance mapping. Defaults to ``True``. When True, it is assumed that ON UPDATE CASCADE is configured on the foreign key in the database, and that the database will handle propagation of an UPDATE from a source column to dependent columns on joined-table rows. When False, it is assumed that the database does not enforce referential integrity and will not be issuing its own CASCADE operation for an update. The unit of work process will emit an UPDATE statement for the dependent columns during a primary key change. .. seealso:: :ref:`passive_updates` - description of a similar feature as used with :func:`_orm.relationship` :paramref:`.mapper.passive_deletes` - supporting ON DELETE CASCADE for joined-table inheritance mappers :param polymorphic_load: Specifies "polymorphic loading" behavior for a subclass in an inheritance hierarchy (joined and single table inheritance only). Valid values are: * "'inline'" - specifies this class should be part of the "with_polymorphic" mappers, e.g. its columns will be included in a SELECT query against the base. * "'selectin'" - specifies that when instances of this class are loaded, an additional SELECT will be emitted to retrieve the columns specific to this subclass. The SELECT uses IN to fetch multiple subclasses at once. .. versionadded:: 1.2 .. seealso:: :ref:`with_polymorphic_mapper_config` :ref:`polymorphic_selectin` :param polymorphic_on: Specifies the column, attribute, or SQL expression used to determine the target class for an incoming row, when inheriting classes are present. May be specified as a string attribute name, or as a SQL expression such as a :class:`_schema.Column` or in a Declarative mapping a :func:`_orm.mapped_column` object. It is typically expected that the SQL expression corresponds to a column in the base-most mapped :class:`.Table`:: class Employee(Base): __tablename__ = 'employee' id: Mapped[int] = mapped_column(primary_key=True) discriminator: Mapped[str] = mapped_column(String(50)) __mapper_args__ = { "polymorphic_on":discriminator, "polymorphic_identity":"employee" } It may also be specified as a SQL expression, as in this example where we use the :func:`.case` construct to provide a conditional approach:: class Employee(Base): __tablename__ = 'employee' id: Mapped[int] = mapped_column(primary_key=True) discriminator: Mapped[str] = mapped_column(String(50)) __mapper_args__ = { "polymorphic_on":case( (discriminator == "EN", "engineer"), (discriminator == "MA", "manager"), else_="employee"), "polymorphic_identity":"employee" } It may also refer to any attribute using its string name, which is of particular use when using annotated column configurations:: class Employee(Base): __tablename__ = 'employee' id: Mapped[int] = mapped_column(primary_key=True) discriminator: Mapped[str] __mapper_args__ = { "polymorphic_on": "discriminator", "polymorphic_identity": "employee" } When setting ``polymorphic_on`` to reference an attribute or expression that's not present in the locally mapped :class:`_schema.Table`, yet the value of the discriminator should be persisted to the database, the value of the discriminator is not automatically set on new instances; this must be handled by the user, either through manual means or via event listeners. A typical approach to establishing such a listener looks like:: from sqlalchemy import event from sqlalchemy.orm import object_mapper @event.listens_for(Employee, "init", propagate=True) def set_identity(instance, *arg, **kw): mapper = object_mapper(instance) instance.discriminator = mapper.polymorphic_identity Where above, we assign the value of ``polymorphic_identity`` for the mapped class to the ``discriminator`` attribute, thus persisting the value to the ``discriminator`` column in the database. .. warning:: Currently, **only one discriminator column may be set**, typically on the base-most class in the hierarchy. "Cascading" polymorphic columns are not yet supported. .. seealso:: :ref:`inheritance_toplevel` :param polymorphic_identity: Specifies the value which identifies this particular class as returned by the column expression referred to by the :paramref:`_orm.Mapper.polymorphic_on` setting. As rows are received, the value corresponding to the :paramref:`_orm.Mapper.polymorphic_on` column expression is compared to this value, indicating which subclass should be used for the newly reconstructed object. .. seealso:: :ref:`inheritance_toplevel` :param properties: A dictionary mapping the string names of object attributes to :class:`.MapperProperty` instances, which define the persistence behavior of that attribute. Note that :class:`_schema.Column` objects present in the mapped :class:`_schema.Table` are automatically placed into ``ColumnProperty`` instances upon mapping, unless overridden. When using Declarative, this argument is passed automatically, based on all those :class:`.MapperProperty` instances declared in the declared class body. .. seealso:: :ref:`orm_mapping_properties` - in the :ref:`orm_mapping_classes_toplevel` :param primary_key: A list of :class:`_schema.Column` objects, or alternatively string names of attribute names which refer to :class:`_schema.Column`, which define the primary key to be used against this mapper's selectable unit. This is normally simply the primary key of the ``local_table``, but can be overridden here. .. versionchanged:: 2.0.2 :paramref:`_orm.Mapper.primary_key` arguments may be indicated as string attribute names as well. .. seealso:: :ref:`mapper_primary_key` - background and example use :param version_id_col: A :class:`_schema.Column` that will be used to keep a running version id of rows in the table. This is used to detect concurrent updates or the presence of stale data in a flush. The methodology is to detect if an UPDATE statement does not match the last known version id, a :class:`~sqlalchemy.orm.exc.StaleDataError` exception is thrown. By default, the column must be of :class:`.Integer` type, unless ``version_id_generator`` specifies an alternative version generator. .. seealso:: :ref:`mapper_version_counter` - discussion of version counting and rationale. :param version_id_generator: Define how new version ids should be generated. Defaults to ``None``, which indicates that a simple integer counting scheme be employed. To provide a custom versioning scheme, provide a callable function of the form:: def generate_version(version): return next_version Alternatively, server-side versioning functions such as triggers, or programmatic versioning schemes outside of the version id generator may be used, by specifying the value ``False``. Please see :ref:`server_side_version_counter` for a discussion of important points when using this option. .. versionadded:: 0.9.0 ``version_id_generator`` supports server-side version number generation. .. seealso:: :ref:`custom_version_counter` :ref:`server_side_version_counter` :param with_polymorphic: A tuple in the form ``(<classes>, <selectable>)`` indicating the default style of "polymorphic" loading, that is, which tables are queried at once. <classes> is any single or list of mappers and/or classes indicating the inherited classes that should be loaded at once. The special value ``'*'`` may be used to indicate all descending classes should be loaded immediately. The second tuple argument <selectable> indicates a selectable that will be used to query for multiple classes. The :paramref:`_orm.Mapper.polymorphic_load` parameter may be preferable over the use of :paramref:`_orm.Mapper.with_polymorphic` in modern mappings to indicate a per-subclass technique of indicating polymorphic loading styles. .. seealso:: :ref:`with_polymorphic_mapper_config`
Add an individual MapperProperty to this mapper. If the mapper has not been configured yet, just adds the property to the initial properties dictionary sent to the constructor. If this Mapper has already been configured, then the given MapperProperty is configured immediately.
def all_orm_descriptors(self) ->
util.ReadOnlyProperties[ InspectionAttr]
:
(source)
¶
A namespace of all :class:`.InspectionAttr` attributes associated with the mapped class. These attributes are in all cases Python :term:`descriptors` associated with the mapped class or its superclasses. This namespace includes attributes that are mapped to the class as well as attributes declared by extension modules. It includes any Python descriptor type that inherits from :class:`.InspectionAttr`. This includes :class:`.QueryableAttribute`, as well as extension types such as :class:`.hybrid_property`, :class:`.hybrid_method` and :class:`.AssociationProxy`. To distinguish between mapped attributes and extension attributes, the attribute :attr:`.InspectionAttr.extension_type` will refer to a constant that distinguishes between different extension types. The sorting of the attributes is based on the following rules: 1. Iterate through the class and its superclasses in order from subclass to superclass (i.e. iterate through ``cls.__mro__``) 2. For each class, yield the attributes in the order in which they appear in ``__dict__``, with the exception of those in step 3 below. In Python 3.6 and above this ordering will be the same as that of the class' construction, with the exception of attributes that were added after the fact by the application or the mapper. 3. If a certain attribute key is also in the superclass ``__dict__``, then it's included in the iteration for that class, and not the class in which it first appeared. The above process produces an ordering that is deterministic in terms of the order in which attributes were assigned to the class. .. versionchanged:: 1.3.19 ensured deterministic ordering for :meth:`_orm.Mapper.all_orm_descriptors`. When dealing with a :class:`.QueryableAttribute`, the :attr:`.QueryableAttribute.property` attribute refers to the :class:`.MapperProperty` property, which is what you get when referring to the collection of mapped properties via :attr:`_orm.Mapper.attrs`. .. warning:: The :attr:`_orm.Mapper.all_orm_descriptors` accessor namespace is an instance of :class:`.OrderedProperties`. This is a dictionary-like object which includes a small number of named methods such as :meth:`.OrderedProperties.items` and :meth:`.OrderedProperties.values`. When accessing attributes dynamically, favor using the dict-access scheme, e.g. ``mapper.all_orm_descriptors[somename]`` over ``getattr(mapper.all_orm_descriptors, somename)`` to avoid name collisions. .. seealso:: :attr:`_orm.Mapper.attrs`
def attrs(self) ->
util.ReadOnlyProperties[ MapperProperty[ Any]]
:
(source)
¶
A namespace of all :class:`.MapperProperty` objects associated this mapper. This is an object that provides each property based on its key name. For instance, the mapper for a ``User`` class which has ``User.name`` attribute would provide ``mapper.attrs.name``, which would be the :class:`.ColumnProperty` representing the ``name`` column. The namespace object can also be iterated, which would yield each :class:`.MapperProperty`. :class:`_orm.Mapper` has several pre-filtered views of this attribute which limit the types of properties returned, including :attr:`.synonyms`, :attr:`.column_attrs`, :attr:`.relationships`, and :attr:`.composites`. .. warning:: The :attr:`_orm.Mapper.attrs` accessor namespace is an instance of :class:`.OrderedProperties`. This is a dictionary-like object which includes a small number of named methods such as :meth:`.OrderedProperties.items` and :meth:`.OrderedProperties.values`. When accessing attributes dynamically, favor using the dict-access scheme, e.g. ``mapper.attrs[somename]`` over ``getattr(mapper.attrs, somename)`` to avoid name collisions. .. seealso:: :attr:`_orm.Mapper.all_orm_descriptors`
str
, state: InstanceState[ _O]
, halt_on: Optional[ Callable[ [ InstanceState[ Any]], bool]]
= None) -> Iterator[ Tuple[ object, Mapper[ Any], InstanceState[ Any], _InstanceDict]]
:
(source)
¶
Iterate each element and its mapper in an object graph, for all relationships that meet the given cascade rule. :param type\_: The name of the cascade rule (i.e. ``"save-update"``, ``"delete"``, etc.). .. note:: the ``"all"`` cascade is not accepted here. For a generic object traversal function, see :ref:`faq_walk_objects`. :param state: The lead InstanceState. child items will be processed per the relationships defined for this object's mapper. :return: the method yields individual object instances. .. seealso:: :ref:`unitofwork_cascades` :ref:`faq_walk_objects` - illustrates a generic function to traverse all objects without relying on cascades.
def column_attrs(self) ->
util.ReadOnlyProperties[ ColumnProperty[ Any]]
:
(source)
¶
Return a namespace of all :class:`.ColumnProperty` properties maintained by this :class:`_orm.Mapper`. .. seealso:: :attr:`_orm.Mapper.attrs` - namespace of all :class:`.MapperProperty` objects.
@util.preload_module(
def composites(self) ->
util.ReadOnlyProperties[ CompositeProperty[ Any]]
:
(source)
¶
Return a namespace of all :class:`.Composite` properties maintained by this :class:`_orm.Mapper`. .. seealso:: :attr:`_orm.Mapper.attrs` - namespace of all :class:`.MapperProperty` objects.
str
, _configure_mappers: bool
= False) -> MapperProperty[ Any]
:
(source)
¶
return a MapperProperty associated with the given key.
Return the identity key for the given instance, based on its primary key attributes. If the instance's state is expired, calling this method will result in a database check to see if the object has been deleted. If the row no longer exists, :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised. This value is typically also found on the instance state under the attribute name `key`.
Tuple[ Any, ...]
, identity_token: Optional[ Any]
= None) -> _IdentityKeyType[ _O]
:
(source)
¶
Return an identity-map key for use in storing/retrieving an item from an identity map. :param primary_key: A list of values indicating the identifier.
Optional[ Union[ Row[ Any], RowMapping]]
, identity_token: Optional[ Any]
= None, adapter: Optional[ ORMAdapter]
= None) -> _IdentityKeyType[ _O]
:
(source)
¶
Return an identity-map key for use in storing/retrieving an item from the identity map. :param row: A :class:`.Row` or :class:`.RowMapping` produced from a result set that selected from the ORM mapped primary key columns. .. versionchanged:: 2.0 :class:`.Row` or :class:`.RowMapping` are accepted for the "row" argument
return true if the other mapper is an inheriting sibling to this one. common parent but different branch
Iterate through the collection including this mapper and all descendant mappers. This includes not just the immediately inheriting mappers but all their inheriting mappers as well. To iterate through an entire hierarchy, use ``mapper.base_mapper.polymorphic_iterator()``.
Return the list of primary key values for the given instance. If the instance's state is expired, calling this method will result in a database check to see if the object has been deleted. If the row no longer exists, :class:`~sqlalchemy.orm.exc.ObjectDeletedError` is raised.
@util.preload_module(
def relationships(self) ->
util.ReadOnlyProperties[ RelationshipProperty[ Any]]
:
(source)
¶
A namespace of all :class:`.Relationship` properties maintained by this :class:`_orm.Mapper`. .. warning:: the :attr:`_orm.Mapper.relationships` accessor namespace is an instance of :class:`.OrderedProperties`. This is a dictionary-like object which includes a small number of named methods such as :meth:`.OrderedProperties.items` and :meth:`.OrderedProperties.values`. When accessing attributes dynamically, favor using the dict-access scheme, e.g. ``mapper.relationships[somename]`` over ``getattr(mapper.relationships, somename)`` to avoid name collisions. .. seealso:: :attr:`_orm.Mapper.attrs` - namespace of all :class:`.MapperProperty` objects.
The collection including this mapper and all descendant mappers. This includes not just the immediately inheriting mappers but all their inheriting mappers as well.
@util.preload_module(
def synonyms(self) ->
util.ReadOnlyProperties[ SynonymProperty[ Any]]
:
(source)
¶
Return a namespace of all :class:`.Synonym` properties maintained by this :class:`_orm.Mapper`. .. seealso:: :attr:`_orm.Mapper.attrs` - namespace of all :class:`.MapperProperty` objects.
The base-most :class:`_orm.Mapper` in an inheritance chain. In a non-inheriting scenario, this attribute will always be this :class:`_orm.Mapper`. In an inheritance scenario, it references the :class:`_orm.Mapper` which is parent to all other :class:`_orm.Mapper` objects in the inheritance chain. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
The :class:`.ClassManager` which maintains event listeners and class-bound descriptors for this :class:`_orm.Mapper`. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
A collection of :class:`_schema.Column` or other scalar expression objects maintained by this :class:`_orm.Mapper`. The collection behaves the same as that of the ``c`` attribute on any :class:`_schema.Table` object, except that only those columns included in this mapping are present, and are keyed based on the attribute name defined in the mapping, not necessarily the ``key`` attribute of the :class:`_schema.Column` itself. Additionally, scalar expressions mapped by :func:`.column_property` are also present here. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
Represent ``True`` if this :class:`_orm.Mapper` is a concrete inheritance mapper. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
Represent ``True`` if this :class:`_orm.Mapper` has been configured. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified. .. seealso:: :func:`.configure_mappers`.
The immediate :class:`_expression.FromClause` which this :class:`_orm.Mapper` refers towards. Typically is an instance of :class:`_schema.Table`, may be any :class:`.FromClause`. The "local" table is the selectable that the :class:`_orm.Mapper` is directly responsible for managing from an attribute access and flush perspective. For non-inheriting mappers, :attr:`.Mapper.local_table` will be the same as :attr:`.Mapper.persist_selectable`. For inheriting mappers, :attr:`.Mapper.local_table` refers to the specific portion of :attr:`.Mapper.persist_selectable` that includes the columns to which this :class:`.Mapper` is loading/persisting, such as a particular :class:`.Table` within a join. .. seealso:: :attr:`_orm.Mapper.persist_selectable`. :attr:`_orm.Mapper.selectable`.
Represent ``True`` if this :class:`_orm.Mapper` is a "non-primary" mapper, e.g. a mapper that is used only to select rows but not for persistence management. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
The :class:`_expression.FromClause` to which this :class:`_orm.Mapper` is mapped. Typically is an instance of :class:`_schema.Table`, may be any :class:`.FromClause`. The :attr:`_orm.Mapper.persist_selectable` is similar to :attr:`.Mapper.local_table`, but represents the :class:`.FromClause` that represents the inheriting class hierarchy overall in an inheritance scenario. :attr.`.Mapper.persist_selectable` is also separate from the :attr:`.Mapper.selectable` attribute, the latter of which may be an alternate subquery used for selecting columns. :attr.`.Mapper.persist_selectable` is oriented towards columns that will be written on a persist operation. .. seealso:: :attr:`_orm.Mapper.selectable`. :attr:`_orm.Mapper.local_table`.
Represent an identifier which is matched against the :attr:`_orm.Mapper.polymorphic_on` column during result row loading. Used only with inheritance, this object can be of any type which is comparable to the type of column represented by :attr:`_orm.Mapper.polymorphic_on`. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
A mapping of "polymorphic identity" identifiers mapped to :class:`_orm.Mapper` instances, within an inheritance scenario. The identifiers can be of any type which is comparable to the type of column represented by :attr:`_orm.Mapper.polymorphic_on`. An inheritance chain of mappers will all reference the same polymorphic map object. The object is used to correlate incoming result rows to target mappers. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
The :class:`_schema.Column` or SQL expression specified as the ``polymorphic_on`` argument for this :class:`_orm.Mapper`, within an inheritance scenario. This attribute is normally a :class:`_schema.Column` instance but may also be an expression, such as one derived from :func:`.cast`. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
An iterable containing the collection of :class:`_schema.Column` objects which comprise the 'primary key' of the mapped table, from the perspective of this :class:`_orm.Mapper`. This list is against the selectable in :attr:`_orm.Mapper.persist_selectable`. In the case of inheriting mappers, some columns may be managed by a superclass mapper. For example, in the case of a :class:`_expression.Join`, the primary key is determined by all of the primary key columns across all tables referenced by the :class:`_expression.Join`. The list is also not necessarily the same as the primary key column collection associated with the underlying tables; the :class:`_orm.Mapper` features a ``primary_key`` argument that can override what the :class:`_orm.Mapper` considers as primary key columns. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
Represent ``True`` if this :class:`_orm.Mapper` is a single table inheritance mapper. :attr:`_orm.Mapper.local_table` will be ``None`` if this flag is set. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
A sequence containing the collection of :class:`_schema.Table` or :class:`_schema.TableClause` objects which this :class:`_orm.Mapper` is aware of. If the mapper is mapped to a :class:`_expression.Join`, or an :class:`_expression.Alias` representing a :class:`_expression.Select`, the individual :class:`_schema.Table` objects that comprise the full construct will be represented here. This is a *read only* attribute determined during mapper construction. Behavior is undefined if directly modified.
An immutable dictionary of attributes which have been decorated using the :func:`_orm.validates` decorator. The dictionary contains string attribute names as keys mapped to the actual validation method.
@util.deprecated(
mapped_table = (source) ¶
Undocumented
The :class:`_schema.FromClause` construct this :class:`_orm.Mapper` selects from by default. Normally, this is equivalent to :attr:`.persist_selectable`, unless the ``with_polymorphic`` feature is in use, in which case the full "polymorphic" selectable is returned.
def _adapt_inherited_property(self, key, prop, init): (source) ¶
Undocumented
def _check_configure(self): (source) ¶
Undocumented
If this mapper is to be a primary mapper (i.e. the non_primary flag is not set), associate this Mapper with the given class and entity name. Subsequent calls to ``class_mapper()`` for the ``class_`` / ``entity`` name combination will return this mapper. Also decorate the `__init__` method on the mapped class to include optional auto-session attachment logic.
Configure an attribute on the mapper representing the 'polymorphic_on' column, if applicable, and not already generated by _configure_properties (which is typical). Also create a setter function which will assign this attribute to the value of the 'polymorphic_identity' upon instance construction, also if applicable. This routine will run when an instance is created.
def _configure_property(self, key:
str
, prop_arg: Union[ KeyedColumnElement[ Any], MapperProperty[ Any]]
, *, init: bool
= True, setparent: bool
= True, warn_for_existing: bool
= False) -> MapperProperty[ Any]
:
(source)
¶
Undocumented
Create a map of all equivalent columns, based on the determination of column pairs that are equated to one another based on inherit condition. This is designed to work with the queries that util.polymorphic_union comes up with, which often don't include the columns from the base table directly (including the subclass table columns only). The resulting structure is a dictionary of columns mapped to lists of equivalent columns, e.g.:: { tablea.col1: {tableb.col1, tablec.col1}, tablea.col2: {tabled.col2} }
return an optional cache key. The cache key is a tuple which can contain any series of objects that are hashable and also identifies this object uniquely within the presence of a larger SQL expression or statement, for the purposes of caching the resulting query. The cache key should be based on the SQL compiled structure that would ultimately be produced. That is, two structures that are composed in exactly the same way should produce the same cache key; any difference in the structures that would affect the SQL string or the type handlers should result in a different cache key. If a structure cannot produce a useful cache key, the NO_CACHE symbol should be added to the anon_map and the method should return None.
create a "get clause" based on the primary key. this is used by query.get() and many-to-one lazyloads to load this item by primary key.
Undocumented
InstanceState[ _O]
, dict_: _InstanceDict
, column: ColumnElement[ Any]
, passive: PassiveFlag
= PassiveFlag.PASSIVE_RETURN_NO_VALUE) -> Any
:
(source)
¶
Undocumented
return True if with_polymorphic[1] is an aliased fromclause, like a subquery. As of #8168, polymorphic adaption with ORMAdapter is used only if this is present.
InstanceState[ _O]
, passive: PassiveFlag
= PassiveFlag.PASSIVE_RETURN_NO_VALUE) -> _IdentityKeyType[ _O]
:
(source)
¶
Undocumented
str
, column: Union[ Sequence[ KeyedColumnElement[ Any]], KeyedColumnElement[ Any]]
) -> ColumnProperty[ Any]
:
(source)
¶
Undocumented
Any
, selectable: Optional[ FromClause]
) -> Sequence[ Mapper[ Any]]
:
(source)
¶
given a with_polymorphic() argument, return the set of mappers it represents. Trims the list of mappers to just those represented within the given selectable, if present. This helps some more legacy-ish mappings.
assemble a WHERE clause which retrieves a given state by primary key, using a minimized set of tables. Applies to a joined-table inheritance mapper where the requested attribute names are only present on joined tables, not the base table. The WHERE clause attempts to include only those tables to minimize joins.
@util.preload_module(
def _pk_synonyms(self) ->
Dict[ str, str]
:
(source)
¶
return a dictionary of {syn_attribute_name: pk_attr_name} for all synonyms that refer to primary key columns
def _polymorphic_adapter(self) ->
Optional[ orm_util.ORMAdapter]
:
(source)
¶
Undocumented
Call the ``init()`` method on all ``MapperProperties`` attached to this mapper. This is a deferred configuration step which is intended to execute once all mappers have been constructed.
This hook is invoked by attribute inspection. E.g. when Query calls: coercions.expect(roles.ColumnsClauseRole, ent, keep_inspect=True) This allows the inspection process run a configure mappers hook.
def _property_from_column(self, key:
str
, column: KeyedColumnElement[ Any]
) -> ColumnProperty[ Any]
:
(source)
¶
generate/update a :class:`.ColumnProperty` given a :class:`_schema.Column` or other SQL expression object.
str
, existing_prop: MapperProperty[ Any]
, warn_only: bool
, incoming_prop: Optional[ ColumnProperty[ Any]]
= None, single_column: Optional[ KeyedColumnElement[ Any]]
= None) -> ColumnProperty[ Any]
:
(source)
¶
Undocumented
Iterable[ Mapper[ Any]]
, innerjoin: bool
) -> FromClause
:
(source)
¶
given a list of mappers (assumed to be within this mapper's inheritance hierarchy), construct an outerjoin amongst those mapper's mapped tables.
def _server_default_col_keys(self) ->
Mapping[ FromClause, FrozenSet[ str]]
:
(source)
¶
Undocumented
def _server_default_cols(self) ->
Mapping[ FromClause, FrozenSet[ Column[ Any]]]
:
(source)
¶
Undocumented
def _server_default_plus_onupdate_propkeys(self) ->
Set[ str]
:
(source)
¶
Undocumented
def _server_onupdate_default_col_keys(self) ->
Mapping[ FromClause, FrozenSet[ str]]
:
(source)
¶
Undocumented
def _server_onupdate_default_cols(self) ->
Mapping[ FromClause, FrozenSet[ Column[ Any]]]
:
(source)
¶
Undocumented
Set the given :class:`_orm.Mapper` as the 'inherits' for this :class:`_orm.Mapper`, assuming this :class:`_orm.Mapper` is concrete and does not already have an inherits.
determine whether a particular property should be implicitly present on the class. This occurs when properties are propagated from an inherited class, or are applied from the columns present in the mapped table.
determine if _MapperEntity or _ORMColumnEntity will need to use polymorphic adaption when setting up a SELECT as well as fetching rows for mapped classes and subclasses against this Mapper. moved here from context.py for #8456 to generalize the ruleset for this condition.
def _subclass_load_via_in(self, entity, polymorphic_from): (source) ¶
Assemble a that can load the columns local to this subclass as a SELECT with IN.
Any
= None, selectable: Union[ Literal[ False, None], FromClause]
= False, innerjoin: bool
= False) -> Tuple[ Sequence[ Mapper[ Any]], FromClause]
:
(source)
¶
Undocumented
def _with_polymorphic_mappers(self) ->
Sequence[ Mapper[ Any]]
:
(source)
¶
Undocumented
return True if this mapper would "selectin" polymorphic load based on the given super mapper, and not from a setting from a subclass. given:: class A: ... class B(A): __mapper_args__ = {"polymorphic_load": "selectin"} class C(B): ... class D(B): __mapper_args__ = {"polymorphic_load": "selectin"} ``inspect(C)._would_selectin_load_only_from_given_mapper(inspect(B))`` returns True, because C does selectin loading because of B's setting. OTOH, ``inspect(D) ._would_selectin_load_only_from_given_mapper(inspect(B))`` returns False, because D does selectin loading because of its own setting; when we are doing a selectin poly load from B, we want to filter out D because it would already have its own selectin poly load set up separately. Added as part of #9373.