class documentation

class MapperProperty(HasCacheKey, _MappedAttribute, InspectionAttr, util.MemoizedSlots):

Known subclasses: sqlalchemy.orm.descriptor_props.DescriptorProperty, sqlalchemy.orm.interfaces.StrategizedProperty

View In Hierarchy

Represent a particular class attribute mapped by _orm.Mapper.

The most common occurrences of .MapperProperty are the mapped _schema.Column, which is represented in a mapping as an instance of .ColumnProperty, and a reference to another class produced by _orm.relationship, represented in the mapping as an instance of .RelationshipProperty.

Method __init__ Undocumented
Method __repr__ Undocumented
Method ​_memoized​_attr​_info Info dictionary associated with the object, allowing user-defined data to be associated with this .InspectionAttr.
Method cascade​_iterator Iterate through instances related to the given instance for a particular 'cascade', starting with this MapperProperty.
Method create​_row​_processor Produce row processing functions and append to the given set of populators lists.
Method do​_init Perform subclass-specific initialization post-mapper-creation steps.
Method init Called after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation initialization steps.
Method instrument​_class Hook called by the Mapper to the property to initiate instrumentation of the class attribute managed by this MapperProperty.
Method merge Merge the attribute represented by this MapperProperty from source to destination object.
Method post​_instrument​_class Perform instrumentation adjustments that need to occur after init() has completed.
Method set​_parent Set the parent mapper that references this MapperProperty.
Method setup Called by Query for the purposes of constructing a SQL statement.
Class Variable __slots__ Undocumented
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable cascade The set of 'cascade' attribute names.
Class Variable is​_property Part of the InspectionAttr interface; states this object is a mapper property.
Instance Variable ​_configure​_finished Undocumented
Instance Variable ​_configure​_started Undocumented
Instance Variable parent Undocumented
Property ​_links​_to​_entity True if this MapperProperty refers to a mapped entity.
Property class​_attribute Return the class-bound descriptor corresponding to this .MapperProperty.

Inherited from HasCacheKey:

Class Variable inherit​_cache Indicate if this .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
Method ​_gen​_cache​_key return an optional cache key.
Method ​_generate​_cache​_key return a cache key.
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 InspectionAttr:

Class Variable ​_is​_internal​_proxy True if this object is an internal proxy object.
Class Variable is​_aliased​_class True if this object is an instance of .AliasedClass.
Class Variable is​_attribute True if this object is a Python :term:`descriptor`.
Class Variable is​_bundle True if this object is an instance of .Bundle.
Class Variable is​_clause​_element True if this object is an instance of _expression.ClauseElement.
Class Variable is​_instance True if this object is an instance of .InstanceState.
Class Variable is​_mapper True if this object is an instance of _orm.Mapper.
Class Variable is​_selectable Return True if this object is an instance of _expression.Selectable.

Inherited from MemoizedSlots:

Method __getattr__ Undocumented
Method ​_fallback​_getattr Undocumented
def __repr__(self):

Undocumented

def _memoized_attr_info(self):

Info dictionary associated with the object, allowing user-defined data to be associated with this .InspectionAttr.

The dictionary is generated when first accessed. Alternatively, it can be specified as a constructor argument to the .column_property, _orm.relationship, or .composite functions.

Changed in version 1.0.0: .MapperProperty.info is also available on extension types via the .InspectionAttrInfo.info attribute, so that it can apply to a wider variety of ORM and extension constructs.

See Also

.QueryableAttribute.info

.SchemaItem.info

def cascade_iterator(self, type_, state, dict_, visited_states, halt_on=None):

Iterate through instances related to the given instance for a particular 'cascade', starting with this MapperProperty.

Return an iterator3-tuples (instance, mapper, state).

Note that the 'cascade' collection on this MapperProperty is checked first for the given type before cascade_iterator is called.

This method typically only applies to RelationshipProperty.

def create_row_processor(self, context, query_entity, path, mapper, result, adapter, populators):
Produce row processing functions and append to the given set of populators lists.
def do_init(self):

Perform subclass-specific initialization post-mapper-creation steps.

This is a template method called by the MapperProperty object's init() method.

def init(self):
Called after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation initialization steps.
def instrument_class(self, mapper):

Hook called by the Mapper to the property to initiate instrumentation of the class attribute managed by this MapperProperty.

The MapperProperty here will typically call out to the attributes module to set up an InstrumentedAttribute.

This step is the first of two steps to set up an InstrumentedAttribute, and is called early in the mapper setup process.

The second step is typically the init_class_attribute step, called from StrategizedProperty via the post_instrument_class() hook. This step assigns additional state to the InstrumentedAttribute (specifically the "impl") which has been determined after the MapperProperty has determined what kind of persistence management it needs to do (e.g. scalar, object, collection, etc).

def merge(self, session, source_state, source_dict, dest_state, dest_dict, load, _recursive, _resolve_conflict_map):
Merge the attribute represented by this MapperProperty from source to destination object.
def post_instrument_class(self, mapper):

Perform instrumentation adjustments that need to occur after init() has completed.

The given Mapper is the Mapper invoking the operation, which may not be the same Mapper as self.parent in an inheritance scenario; however, Mapper will always at least be a sub-mapper of self.parent.

This method is typically used by StrategizedProperty, which delegates it to LoaderStrategy.init_class_attribute() to perform final setup on the class-bound InstrumentedAttribute.

def set_parent(self, parent, init):

Set the parent mapper that references this MapperProperty.

This method is overridden by some subclasses to perform extra setup when the mapper is first known.

def setup(self, context, query_entity, path, adapter, **kwargs):

Called by Query for the purposes of constructing a SQL statement.

Each MapperProperty associated with the target mapper processes the statement referenced by the query context, adding columns and/or criterion as appropriate.

__slots__: tuple[str, ...] =
_cache_key_traversal =

Undocumented

cascade =

The set of 'cascade' attribute names.

This collection is checked before the 'cascade_iterator' method is called.

The collection typically only applies to a RelationshipProperty.

is_property: bool =
Part of the InspectionAttr interface; states this object is a mapper property.
_configure_finished: bool =

Undocumented

_configure_started: bool =

Undocumented

parent =

Undocumented

@property
_links_to_entity =

True if this MapperProperty refers to a mapped entity.

Should only be True for RelationshipProperty, False for all others.

@property
class_attribute =

Return the class-bound descriptor corresponding to this .MapperProperty.

This is basically a getattr() call:

return getattr(self.parent.class_, self.key)

I.e. if this .MapperProperty were named addresses, and the class to which it is mapped is User, this sequence is possible:

>>> from sqlalchemy import inspect
>>> mapper = inspect(User)
>>> addresses_property = mapper.attrs.addresses
>>> addresses_property.class_attribute is User.addresses
True
>>> User.addresses.property is addresses_property
True