class documentation

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_element__ Undocumented
Method __init__ Direct constructor for a new :class:`_orm.Mapper` object.
Method __repr__ Undocumented
Method __str__ Undocumented
Method add_properties Add the given dictionary of properties to this mapper, using `add_property`.
Method add_property Add an individual MapperProperty to this mapper.
Method all_orm_descriptors 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_iterator Iterate each element and its mapper in an object graph, for all relationships that meet the given cascade rule.
Method column_attrs Return a namespace of all :class:`.ColumnProperty` properties maintained by this :class:`_orm.Mapper`.
Method common_parent 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_property return a MapperProperty associated with the given key.
Method get_property_by_column Given a :class:`_schema.Column` object, return the :class:`.MapperProperty` which maps this column.
Method has_property Undocumented
Method identity_key_from_instance Return the identity key for the given instance, based on its primary key attributes.
Method identity_key_from_primary_key Return an identity-map key for use in storing/retrieving an item from an identity map.
Method identity_key_from_row Return an identity-map key for use in storing/retrieving an item from the identity map.
Method is_sibling 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_to_root Undocumented
Method polymorphic_iterator Iterate through the collection including this mapper and all descendant mappers.
Method primary_key_from_instance Return the list of primary key values for the given instance.
Method primary_mapper 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_and_descendants 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_mapper Part of the inspection API.
Class Variable represents_outer_join Undocumented
Instance Variable allow_partial_pks Undocumented
Instance Variable always_refresh Undocumented
Instance Variable base_mapper 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_manager The :class:`.ClassManager` which maintains event listeners and class-bound descriptors for this :class:`_orm.Mapper`.
Instance Variable column_prefix 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_deleted_rows Undocumented
Instance Variable eager_defaults Undocumented
Instance Variable exclude_properties Undocumented
Instance Variable include_properties Undocumented
Instance Variable inherit_condition Undocumented
Instance Variable inherit_foreign_keys Undocumented
Instance Variable inherits References the :class:`_orm.Mapper` which this :class:`_orm.Mapper` inherits from, if any.
Instance Variable legacy_is_orphan Undocumented
Instance Variable local_table The immediate :class:`_expression.FromClause` which this :class:`_orm.Mapper` refers towards.
Instance Variable non_primary 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_deletes Undocumented
Instance Variable passive_updates Undocumented
Instance Variable persist_selectable The :class:`_expression.FromClause` to which this :class:`_orm.Mapper` is mapped.
Instance Variable polymorphic_abstract Undocumented
Instance Variable polymorphic_identity Represent an identifier which is matched against the :attr:`_orm.Mapper.polymorphic_on` column during result row loading.
Instance Variable polymorphic_load Undocumented
Instance Variable polymorphic_map A mapping of "polymorphic identity" identifiers mapped to :class:`_orm.Mapper` instances, within an inheritance scenario.
Instance Variable polymorphic_on 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_key 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_id_col Undocumented
Instance Variable version_id_generator Undocumented
Instance Variable version_id_prop Undocumented
Instance Variable with_polymorphic Undocumented
Property entity Part of the inspection API.
Property entity_namespace Undocumented
Property iterate_properties return an iterator of all MapperProperty objects.
Property mapped_table Undocumented
Property mapper Part of the inspection API.
Property primary_base_mapper Undocumented
Property select_identity_token Undocumented
Property selectable The :class:`_schema.FromClause` construct this :class:`_orm.Mapper` selects from by default.
Method _acceptable_polymorphic_identities Undocumented
Method _adapt_inherited_property Undocumented
Method _add_with_polymorphic_subclass Undocumented
Method _all_pk_cols Undocumented
Method _canload Undocumented
Method _check_configure Undocumented
Method _columns_plus_keys Undocumented
Method _compiled_cache Undocumented
Method _configure_class_instrumentation 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_inheritance Configure settings related to inheriting and/or inherited mappers being present.
Method _configure_pks Undocumented
Method _configure_polymorphic_setter 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_properties Undocumented
Method _configure_property Undocumented
Method _dataclass_fields Undocumented
Method _equivalent_columns 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_memoizations Undocumented
Method _filter_properties Undocumented
Method _gen_cache_key return an optional cache key.
Method _get_clause 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_committed_attr_by_column Undocumented
Method _get_committed_state_attr_by_column Undocumented
Method _get_state_attr_by_column Undocumented
Method _has_aliased_polymorphic_fromclause return True if with_polymorphic[1] is an aliased fromclause, like a subquery.
Method _identity_key_from_state Undocumented
Method _identity_key_props Undocumented
Method _insert_cols_as_none Undocumented
Method _insert_cols_evaluating_none Undocumented
Method _is_orphan Undocumented
Method _is_userland_descriptor Undocumented
Method _iterate_polymorphic_properties Return an iterator of MapperProperty objects which will render into a SELECT.
Method _iterate_to_target_viawpoly Undocumented
Method _log Undocumented
Method _log_debug Undocumented
Method _make_prop_from_column Undocumented
Method _mappers_from_spec given a with_polymorphic() argument, return the set of mappers it represents.
Method _memo Undocumented
Method _multiple_persistence_tables Undocumented
Method _optimized_get_statement assemble a WHERE clause which retrieves a given state by primary key, using a minimized set of tables.
Method _persistent_sortkey_fn Undocumented
Method _pk_attr_keys_by_table Undocumented
Method _pk_keys_by_table Undocumented
Method _pk_synonyms return a dictionary of {syn_attribute_name: pk_attr_name} for all synonyms that refer to primary key columns
Method _polymorphic_adapter Undocumented
Method _polymorphic_properties Undocumented
Method _post_configure_properties Call the ``init()`` method on all ``MapperProperties`` attached to this mapper.
Method _post_inspect This hook is invoked by attribute inspection.
Method _prefer_eager_defaults Undocumented
Method _primary_key_propkeys Undocumented
Method _prop_set Undocumented
Method _property_from_column generate/update a :class:`.ColumnProperty` given a :class:`_schema.Column` or other SQL expression object.
Method _propkey_to_col Undocumented
Method _reconcile_prop_with_incoming_columns Undocumented
Method _result_has_identity_key Undocumented
Method _selectable_from_mappers 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_default_col_keys Undocumented
Method _server_default_cols Undocumented
Method _server_default_plus_onupdate_propkeys Undocumented
Method _server_onupdate_default_col_keys Undocumented
Method _server_onupdate_default_cols Undocumented
Method _set_committed_state_attr_by_column Undocumented
Method _set_concrete_base 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_dispose_flags Undocumented
Method _set_polymorphic_on Undocumented
Method _set_state_attr_by_column Undocumented
Method _set_with_polymorphic Undocumented
Method _should_exclude determine whether a particular property should be implicitly present on the class.
Method _should_select_with_poly_adapter 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_selectin_load Undocumented
Method _should_undefer_in_wildcard Undocumented
Method _single_table_criterion Undocumented
Method _sorted_tables Undocumented
Method _str_arg_to_mapped_col Undocumented
Method _subclass_load_via_in Assemble a that can load the columns local to this subclass as a SELECT with IN.
Method _subclass_load_via_in_mapper Undocumented
Method _version_id_has_server_side_value Undocumented
Method _version_id_prop Undocumented
Method _with_polymorphic_args Undocumented
Method _with_polymorphic_mappers Undocumented
Method _with_polymorphic_selectable Undocumented
Method _would_selectin_load_only_from_given_mapper 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_selectinload_combinations_cache Undocumented
Class Variable _configure_failed Undocumented
Instance Variable _all_tables Undocumented
Instance Variable _clause_adapter Undocumented
Instance Variable _cols_by_table Undocumented
Instance Variable _columntoproperty Undocumented
Instance Variable _compiled_cache_size Undocumented
Instance Variable _delete_orphans Undocumented
Instance Variable _dependency_processors Undocumented
Instance Variable _dispose_called Undocumented
Instance Variable _identity_class Undocumented
Instance Variable _inheriting_mappers Undocumented
Instance Variable _inherits_equated_pairs Undocumented
Instance Variable _init_properties Undocumented
Instance Variable _memoized_values Undocumented
Instance Variable _pks_by_table Undocumented
Instance Variable _polymorphic_attr_key Undocumented
Instance Variable _primary_key_argument Undocumented
Instance Variable _props Undocumented
Instance Variable _readonly_props Undocumented
Instance Variable _ready_for_configure Undocumented
Instance Variable _reconstructor Undocumented
Instance Variable _requires_row_aliasing Undocumented
Instance Variable _set_polymorphic_identity Undocumented
Instance Variable _sort_key Undocumented
Instance Variable _validate_polymorphic_identity Undocumented
Property _all_column_expressions Undocumented
Property _log_desc Undocumented
Property _path_registry Undocumented
Property _table_to_equated 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_name Undocumented

Inherited from FromClauseRole (via ORMFromClauseRole, StrictFromClauseRole):

Class Variable named_with_column Undocumented
Class Variable _is_subquery Undocumented

Inherited from ColumnsClauseRole (via ORMFromClauseRole, StrictFromClauseRole, FromClauseRole, ORMEntityColumnsClauseRole, ORMColumnsClauseRole):

Property _select_iterable Undocumented

Inherited from AllowsLambdaRole (via ORMFromClauseRole, StrictFromClauseRole, FromClauseRole, ORMEntityColumnsClauseRole, ORMColumnsClauseRole, ColumnsClauseRole, JoinTargetRole):

Class Variable allows_lambda Undocumented

Inherited from UsesInspection (via ORMFromClauseRole, StrictFromClauseRole, FromClauseRole, ORMEntityColumnsClauseRole, ORMColumnsClauseRole, ColumnsClauseRole, JoinTargetRole, AllowsLambdaRole):

Class Variable uses_inspection Undocumented

Inherited from MemoizedHasCacheKey (via ORMFromClauseRole, StrictFromClauseRole, FromClauseRole, ORMEntityColumnsClauseRole, ORMColumnsClauseRole, ColumnsClauseRole, JoinTargetRole, AllowsLambdaRole, UsesInspection, ColumnListRole, StructuralRole, TypedColumnsClauseRole):

Method _generate_cache_key return a cache key.

Inherited from HasCacheKey (via ORMFromClauseRole, StrictFromClauseRole, FromClauseRole, ORMEntityColumnsClauseRole, ORMColumnsClauseRole, ColumnsClauseRole, JoinTargetRole, AllowsLambdaRole, UsesInspection, ColumnListRole, StructuralRole, TypedColumnsClauseRole, MemoizedHasCacheKey):

Class Variable inherit_cache Indicate if this :class:`.HasCacheKey` instance should make use of the cache key generation scheme used by its immediate superclass.
Class Method _generate_cache_attrs generate cache key dispatcher for a new class.
Class Method _generate_cache_key_for_object Undocumented
Class Variable _generated_cache_key_traversal Undocumented
Class Variable _hierarchy_supports_caching 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_has_cache_key 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_name Undocumented
Method _should_log_debug Undocumented
Method _should_log_info Undocumented
Class Variable _echo Undocumented
@HasMemoized.memoized_instancemethod
def __clause_element__(self): (source)

Undocumented

@util.deprecated_params(non_primary=('1.3', 'The :paramref:`.mapper.non_primary` parameter is deprecated, and will be removed in a future release. The functionality of non primary mappers is now better suited using the :class:`.AliasedClass` construct, which can also be used as the target of a :func:`_orm.relationship` in 1.3.'))
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`

def __repr__(self) -> str: (source)

Undocumented

def __str__(self) -> str: (source)

Undocumented

def add_properties(self, dict_of_properties): (source)

Add the given dictionary of properties to this mapper, using `add_property`.

def add_property(self, key: str, prop: Union[Column[Any], MapperProperty[Any]]): (source)

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.

@HasMemoized.memoized_attribute
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`

@HasMemoized.memoized_attribute
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`

def cascade_iterator(self, type_: 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.

@HasMemoized.memoized_attribute
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.

def common_parent(self, other: Mapper[Any]) -> bool: (source)

Return true if the given mapper shares a common inherited parent as this mapper.

@HasMemoized.memoized_attribute
@util.preload_module('sqlalchemy.orm.descriptor_props')
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.

def get_property(self, key: str, _configure_mappers: bool = False) -> MapperProperty[Any]: (source)

return a MapperProperty associated with the given key.

def get_property_by_column(self, column: ColumnElement[_T]) -> MapperProperty[_T]: (source)

Given a :class:`_schema.Column` object, return the :class:`.MapperProperty` which maps this column.

def has_property(self, key: str) -> bool: (source)

Undocumented

def identity_key_from_instance(self, instance: _O) -> _IdentityKeyType[_O]: (source)

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`.

def identity_key_from_primary_key(self, primary_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.

def identity_key_from_row(self, row: 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

def is_sibling(self, other: Mapper[Any]) -> bool: (source)

return true if the other mapper is an inheriting sibling to this one. common parent but different branch

def isa(self, other: Mapper[Any]) -> bool: (source)

Return True if the this mapper inherits from the given mapper.

def iterate_to_root(self) -> Iterator[Mapper[Any]]: (source)

Undocumented

def polymorphic_iterator(self) -> Iterator[Mapper[Any]]: (source)

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()``.

def primary_key_from_instance(self, instance: _O) -> Tuple[Any, ...]: (source)

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.

def primary_mapper(self) -> Mapper[Any]: (source)

Return the primary mapper corresponding to this mapper's class key (class).

@HasMemoized.memoized_attribute
@util.preload_module('sqlalchemy.orm.relationships')
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.

@HasMemoized.memoized_attribute
def self_and_descendants(self) -> Sequence[Mapper[Any]]: (source)

The collection including this mapper and all descendant mappers. This includes not just the immediately inheriting mappers but all their inheriting mappers as well.

@HasMemoized.memoized_attribute
@util.preload_module('sqlalchemy.orm.descriptor_props')
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.

dispatch: dispatcher[Mapper[_O]] = (source)

Undocumented

is_mapper: bool = (source)

Part of the inspection API.

represents_outer_join: bool = (source)

Undocumented

allow_partial_pks: bool = (source)

Undocumented

always_refresh: bool = (source)

Undocumented

base_mapper = (source)

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.

Undocumented

A synonym for :attr:`_orm.Mapper.columns`.

The class to which this :class:`_orm.Mapper` is mapped.

class_manager = (source)

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.

column_prefix = (source)

Undocumented

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.

concrete: bool = (source)

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.

configured: bool = (source)

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`.

confirm_deleted_rows: bool = (source)

Undocumented

eager_defaults = (source)

Undocumented

exclude_properties = (source)

Undocumented

include_properties = (source)

Undocumented

Undocumented

inherit_foreign_keys = (source)

Undocumented

inherits = (source)

References the :class:`_orm.Mapper` which this :class:`_orm.Mapper` inherits from, if any.

legacy_is_orphan = (source)

Undocumented

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`.

non_primary: bool = (source)

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.

passive_deletes = (source)

Undocumented

passive_updates = (source)

Undocumented

persist_selectable = (source)

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`.

polymorphic_abstract = (source)

Undocumented

polymorphic_identity: Optional[Any] = (source)

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.

polymorphic_load = (source)

Undocumented

polymorphic_map = (source)

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.

polymorphic_on = (source)

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.

primary_key = (source)

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.

registry = (source)

Undocumented

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.

validators: util.immutabledict[str, Tuple[str, Dict[str, Any]]] = (source)

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.

version_id_col = (source)

Undocumented

version_id_generator = (source)

Undocumented

version_id_prop = (source)

Undocumented

with_polymorphic = (source)

Undocumented

Part of the inspection API. Returns self.class\_.

@property
entity_namespace = (source)

Undocumented

@property
iterate_properties = (source)

return an iterator of all MapperProperty objects.

@util.non_memoized_property
@util.deprecated('1.3', 'Use .persist_selectable')
mapped_table = (source)

Undocumented

Part of the inspection API. Returns self.

@property
primary_base_mapper: Mapper[Any] = (source)

Undocumented

@util.memoized_property
select_identity_token = (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.

@HasMemoized.memoized_attribute
def _acceptable_polymorphic_identities(self): (source)

Undocumented

@util.preload_module('sqlalchemy.orm.descriptor_props')
def _adapt_inherited_property(self, key, prop, init): (source)

Undocumented

def _add_with_polymorphic_subclass(self, mapper): (source)

Undocumented

@HasMemoized.memoized_attribute
def _all_pk_cols(self): (source)

Undocumented

def _canload(self, state: InstanceState[Any], allow_subtypes: bool) -> bool: (source)

Undocumented

@util.langhelpers.tag_method_for_warnings('This warning originated from the `configure_mappers()` process, which was invoked automatically in response to a user-initiated operation.', sa_exc.SAWarning)
def _check_configure(self): (source)

Undocumented

def _columns_plus_keys(self, polymorphic_mappers=()): (source)

Undocumented

@HasMemoized.memoized_attribute
def _compiled_cache(self): (source)

Undocumented

def _configure_class_instrumentation(self): (source)

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.

def _configure_inheritance(self): (source)

Configure settings related to inheriting and/or inherited mappers being present.

def _configure_pks(self): (source)

Undocumented

def _configure_polymorphic_setter(self, init=False): (source)

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_properties(self): (source)

Undocumented

@util.preload_module('sqlalchemy.orm.descriptor_props')
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

@HasMemoized.memoized_attribute
def _dataclass_fields(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _equivalent_columns(self) -> _EquivalentColumnMap: (source)

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} }

def _expire_memoizations(self): (source)

Undocumented

def _filter_properties(self, type_: Type[_MP]) -> util.ReadOnlyProperties[_MP]: (source)

Undocumented

def _gen_cache_key(self, anon_map, bindparams): (source)

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.

@HasMemoized.memoized_attribute
def _get_clause(self): (source)

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.

def _get_committed_attr_by_column(self, obj, column): (source)

Undocumented

def _get_committed_state_attr_by_column(self, state, dict_, column, passive=PassiveFlag.PASSIVE_RETURN_NO_VALUE): (source)

Undocumented

def _get_state_attr_by_column(self, state: InstanceState[_O], dict_: _InstanceDict, column: ColumnElement[Any], passive: PassiveFlag = PassiveFlag.PASSIVE_RETURN_NO_VALUE) -> Any: (source)

Undocumented

@HasMemoized.memoized_attribute
def _has_aliased_polymorphic_fromclause(self): (source)

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.

def _identity_key_from_state(self, state: InstanceState[_O], passive: PassiveFlag = PassiveFlag.PASSIVE_RETURN_NO_VALUE) -> _IdentityKeyType[_O]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _identity_key_props(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _insert_cols_as_none(self): (source)

Undocumented

@HasMemoized_ro_memoized_attribute
def _insert_cols_evaluating_none(self): (source)

Undocumented

def _is_orphan(self, state: InstanceState[_O]) -> bool: (source)

Undocumented

def _is_userland_descriptor(self, assigned_name: str, obj: Any) -> bool: (source)

Undocumented

def _iterate_polymorphic_properties(self, mappers=None): (source)

Return an iterator of MapperProperty objects which will render into a SELECT.

def _iterate_to_target_viawpoly(self, mapper): (source)

Undocumented

def _log(self, msg: str, *args: Any): (source)

Undocumented

def _log_debug(self, msg: str, *args: Any): (source)

Undocumented

def _make_prop_from_column(self, key: str, column: Union[Sequence[KeyedColumnElement[Any]], KeyedColumnElement[Any]]) -> ColumnProperty[Any]: (source)

Undocumented

def _mappers_from_spec(self, spec: 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.

def _memo(self, key: Any, callable_: Callable[[], _T]) -> _T: (source)

Undocumented

@HasMemoized.memoized_attribute
def _multiple_persistence_tables(self): (source)

Undocumented

def _optimized_get_statement(self, state, attribute_names): (source)

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.

@HasMemoized.memoized_attribute
def _persistent_sortkey_fn(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _pk_attr_keys_by_table(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _pk_keys_by_table(self): (source)

Undocumented

@HasMemoized.memoized_attribute
@util.preload_module('sqlalchemy.orm.descriptor_props')
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

@HasMemoized.memoized_attribute
def _polymorphic_adapter(self) -> Optional[orm_util.ORMAdapter]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _polymorphic_properties(self): (source)

Undocumented

def _post_configure_properties(self): (source)

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.

@HasMemoized.memoized_attribute
def _post_inspect(self): (source)

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 _prefer_eager_defaults(self, dialect, table): (source)

Undocumented

@HasMemoized.memoized_attribute
def _primary_key_propkeys(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _prop_set(self): (source)

Undocumented

@util.preload_module('sqlalchemy.orm.descriptor_props')
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.

@HasMemoized.memoized_attribute
def _propkey_to_col(self): (source)

Undocumented

def _reconcile_prop_with_incoming_columns(self, key: str, existing_prop: MapperProperty[Any], warn_only: bool, incoming_prop: Optional[ColumnProperty[Any]] = None, single_column: Optional[KeyedColumnElement[Any]] = None) -> ColumnProperty[Any]: (source)

Undocumented

def _result_has_identity_key(self, result, adapter=None): (source)

Undocumented

def _selectable_from_mappers(self, mappers: 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.

@HasMemoized.memoized_attribute
def _server_default_col_keys(self) -> Mapping[FromClause, FrozenSet[str]]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _server_default_cols(self) -> Mapping[FromClause, FrozenSet[Column[Any]]]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _server_default_plus_onupdate_propkeys(self) -> Set[str]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _server_onupdate_default_col_keys(self) -> Mapping[FromClause, FrozenSet[str]]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _server_onupdate_default_cols(self) -> Mapping[FromClause, FrozenSet[Column[Any]]]: (source)

Undocumented

def _set_committed_state_attr_by_column(self, state, dict_, column, value): (source)

Undocumented

def _set_concrete_base(self, mapper): (source)

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.

def _set_dispose_flags(self): (source)

Undocumented

def _set_polymorphic_on(self, polymorphic_on): (source)

Undocumented

def _set_state_attr_by_column(self, state, dict_, column, value): (source)

Undocumented

def _set_with_polymorphic(self, with_polymorphic: Optional[_WithPolymorphicArg]): (source)

Undocumented

def _should_exclude(self, name, assigned_name, local, column): (source)

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.

@HasMemoized.memoized_attribute
def _should_select_with_poly_adapter(self): (source)

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 _should_selectin_load(self, enabled_via_opt, polymorphic_from): (source)

Undocumented

@HasMemoized.memoized_attribute
def _should_undefer_in_wildcard(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _single_table_criterion(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _sorted_tables(self): (source)

Undocumented

def _str_arg_to_mapped_col(self, argname: str, key: str) -> Column[Any]: (source)

Undocumented

@util.preload_module('sqlalchemy.orm.strategy_options')
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.

@HasMemoized.memoized_attribute
def _subclass_load_via_in_mapper(self): (source)

Undocumented

@HasMemoized.memoized_attribute
def _version_id_has_server_side_value(self) -> bool: (source)

Undocumented

@HasMemoized.memoized_attribute
def _version_id_prop(self): (source)

Undocumented

def _with_polymorphic_args(self, spec: Any = None, selectable: Union[Literal[False, None], FromClause] = False, innerjoin: bool = False) -> Tuple[Sequence[Mapper[Any]], FromClause]: (source)

Undocumented

@HasMemoized.memoized_attribute
def _with_polymorphic_mappers(self) -> Sequence[Mapper[Any]]: (source)

Undocumented

@HasMemoized_ro_memoized_attribute
def _with_polymorphic_selectable(self) -> FromClause: (source)

Undocumented

def _would_selectin_load_only_from_given_mapper(self, super_mapper): (source)

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.

@HasMemoized.memoized_attribute
def _would_selectinload_combinations_cache(self): (source)

Undocumented

_configure_failed: Any = (source)

Undocumented

_all_tables = (source)

Undocumented

_clause_adapter = (source)

Undocumented

_cols_by_table: dict = (source)

Undocumented

_columntoproperty = (source)

Undocumented

_compiled_cache_size = (source)

Undocumented

_delete_orphans: List[Tuple[str, Type[Any]]] = (source)

Undocumented

_dependency_processors: List[DependencyProcessor] = (source)

Undocumented

_dispose_called: bool = (source)

Undocumented

_identity_class = (source)

Undocumented

_inheriting_mappers = (source)

Undocumented

_inherits_equated_pairs = (source)

Undocumented

_init_properties: Dict[str, MapperProperty[Any]] = (source)

Undocumented

_memoized_values: Dict[Any, Callable[[], Any]] = (source)

Undocumented

_pks_by_table: dict = (source)

Undocumented

_polymorphic_attr_key = (source)

Undocumented

_primary_key_argument = (source)

Undocumented

Undocumented

_readonly_props = (source)

Undocumented

_ready_for_configure: bool = (source)

Undocumented

_reconstructor = (source)

Undocumented

_requires_row_aliasing: bool = (source)

Undocumented

_set_polymorphic_identity = (source)

Undocumented

_sort_key = (source)

Undocumented

_validate_polymorphic_identity = (source)

Undocumented

@property
_all_column_expressions = (source)

Undocumented

Undocumented

@util.memoized_property
_path_registry: CachingEntityRegistry = (source)

Undocumented

@util.memoized_property
_table_to_equated = (source)

memoized map of tables to collections of columns to be synchronized upwards to the base mapper.