MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / configure_mappers

Function configure_mappers

lib/sqlalchemy/orm/mapper.py:4101–4181  ·  lib/sqlalchemy/orm/mapper.py::configure_mappers

Initialize the inter-mapper relationships of all mappers that have been constructed thus far across all :class:`_orm.registry` collections. The configure step is used to reconcile and initialize the :func:`_orm.relationship` linkages between mapped classes, as well as to invoke

()

Source from the content-addressed store, hash-verified

4099
4100
4101def configure_mappers() -> None:
4102 class="st">"""Initialize the inter-mapper relationships of all mappers that
4103 have been constructed thus far across all :class:`_orm.registry`
4104 collections.
4105
4106 The configure step is used to reconcile and initialize the
4107 :func:`_orm.relationship` linkages between mapped classes, as well as to
4108 invoke configuration events such as the
4109 :meth:`_orm.MapperEvents.before_configured` and
4110 :meth:`_orm.MapperEvents.after_configured`, which may be used by ORM
4111 extensions or user-defined extension hooks.
4112
4113 Mapper configuration is normally invoked automatically, the first time
4114 mappings from a particular :class:`_orm.registry` are used, as well as
4115 whenever mappings are used and additional not-yet-configured mappers have
4116 been constructed. The automatic configuration process however is local only
4117 to the :class:`_orm.registry` involving the target mapper and any related
4118 :class:`_orm.registry` objects which it may depend on; this is
4119 equivalent to invoking the :meth:`_orm.registry.configure` method
4120 on a particular :class:`_orm.registry`.
4121
4122 By contrast, the :func:`_orm.configure_mappers` function will invoke the
4123 configuration process on all :class:`_orm.registry` objects that
4124 exist in memory, and may be useful for scenarios where many individual
4125 :class:`_orm.registry` objects that are nonetheless interrelated are
4126 in use.
4127
4128 .. versionchanged:: 1.4
4129
4130 As of SQLAlchemy 1.4.0b2, this function works on a
4131 per-:class:`_orm.registry` basis, locating all :class:`_orm.registry`
4132 objects present and invoking the :meth:`_orm.registry.configure` method
4133 on each. The :meth:`_orm.registry.configure` method may be preferred to
4134 limit the configuration of mappers to those local to a particular
4135 :class:`_orm.registry` and/or declarative base class.
4136
4137 Points at which automatic configuration is invoked include when a mapped
4138 class is instantiated into an instance, as well as when ORM queries
4139 are emitted using :meth:`.Session.query` or :meth:`_orm.Session.execute`
4140 with an ORM-enabled statement.
4141
4142 The mapper configure process, whether invoked by
4143 :func:`_orm.configure_mappers` or from :meth:`_orm.registry.configure`,
4144 provides several event hooks that can be used to augment the mapper
4145 configuration step. These hooks include:
4146
4147 * :meth:`.MapperEvents.before_configured` - called once before
4148 :func:`.configure_mappers` or :meth:`_orm.registry.configure` does any
4149 work; this can be used to establish additional options, properties, or
4150 related mappings before the operation proceeds.
4151
4152 * :meth:`.RegistryEvents.before_configured` - Like
4153 :meth:`.MapperEvents.before_configured`, but local to a specific
4154 :class:`_orm.registry`.
4155
4156 .. versionadded:: 2.1 - added :meth:`.RegistryEvents.before_configured`
4157
4158 * :meth:`.MapperEvents.mapper_configured` - called as each individual

Calls 2

_configure_registriesFunction · 0.85
_all_registriesFunction · 0.85