class RelationshipProperty(_IntrospectsAnnotations, StrategizedProperty[
Known subclasses: sqlalchemy.orm.relationships.Relationship
Describes an object property that holds a single item or list of items that correspond to a related database table. Public constructor is the :func:`_orm.relationship` function. .. seealso:: :ref:`relationship_config_toplevel`
Class |
|
Produce boolean, comparison, and other operators for :class:`.RelationshipProperty` attributes. |
Method | __init__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | cascade |
Undocumented |
Method | cascade |
Iterate through instances related to the given instance for a particular 'cascade', starting with this MapperProperty. |
Method | declarative |
Perform class-specific initializaton at early declarative scanning time. |
Method | do |
Perform subclass-specific initialization post-mapper-creation steps. |
Method | instrument |
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. |
Class Variable | inherit |
:meta private: |
Instance Variable | active |
Undocumented |
Instance Variable | argument |
Undocumented |
Instance Variable | back |
Undocumented |
Instance Variable | backref |
Undocumented |
Instance Variable | collection |
Undocumented |
Instance Variable | comparator |
Undocumented |
Instance Variable | direction |
Undocumented |
Instance Variable | distinct |
Undocumented |
Instance Variable | doc |
optional documentation string |
Instance Variable | enable |
Undocumented |
Instance Variable | entity |
Return the target mapped entity, which is an inspect() of the class or aliased class that is referred towards. |
Instance Variable | innerjoin |
Undocumented |
Instance Variable | join |
Undocumented |
Instance Variable | lazy |
Undocumented |
Instance Variable | load |
Undocumented |
Instance Variable | local |
Undocumented |
Instance Variable | local |
Undocumented |
Instance Variable | omit |
Undocumented |
Instance Variable | order |
Undocumented |
Instance Variable | passive |
Undocumented |
Instance Variable | passive |
Undocumented |
Instance Variable | post |
Undocumented |
Instance Variable | primaryjoin |
Undocumented |
Instance Variable | query |
Undocumented |
Instance Variable | remote |
Undocumented |
Instance Variable | secondary |
Undocumented |
Instance Variable | secondary |
Undocumented |
Instance Variable | secondaryjoin |
Undocumented |
Instance Variable | single |
Undocumented |
Instance Variable | strategy |
Undocumented |
Instance Variable | sync |
Undocumented |
Instance Variable | synchronize |
Undocumented |
Instance Variable | target |
Undocumented |
Instance Variable | uselist |
Undocumented |
Instance Variable | viewonly |
Undocumented |
Property | cascade |
Return the current cascade setting for this :class:`.RelationshipProperty`. |
Property | mapper |
Return the targeted :class:`_orm.Mapper` for this :class:`.RelationshipProperty`. |
Static Method | _check |
Undocumented |
Method | _add |
Undocumented |
Method | _check |
Undocumented |
Method | _check |
Test that this relationship is legal, warn about inheritance conflicts. |
Method | _columns |
Return True if all columns in the given collection are mapped by the tables referenced by this :class:`.RelationshipProperty`. |
Method | _create |
Undocumented |
Method | _generate |
Interpret the 'backref' instruction to create a :func:`_orm.relationship` complementary to this one. |
Method | _get |
Create the callable that is used in a many-to-one expression. |
Method | _lazy |
Undocumented |
Method | _optimized |
Undocumented |
Method | _persists |
Return True if this property will persist values on behalf of the given mapper. |
Method | _post |
Undocumented |
Method | _process |
Convert incoming configuration arguments to their proper form. |
Method | _set |
Undocumented |
Method | _setup |
Undocumented |
Method | _setup |
Undocumented |
Method | _setup |
Undocumented |
Method | _value |
Return a list of tuples (state, obj) for the given key. |
Method | _warn |
Undocumented |
Method | _with |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _links |
True if this MapperProperty refers to a mapped entity. |
Class Variable | _persistence |
Undocumented |
Instance Variable | _calculated |
Undocumented |
Instance Variable | _cascade |
Undocumented |
Instance Variable | _dependency |
Undocumented |
Instance Variable | _init |
Undocumented |
Instance Variable | _join |
Undocumented |
Instance Variable | _lazy |
Undocumented |
Instance Variable | _legacy |
Undocumented |
Instance Variable | _overlaps |
Undocumented |
Instance Variable | _reverse |
Undocumented |
Instance Variable | _user |
Undocumented |
Property | _clsregistry |
Undocumented |
Property | _clsregistry |
Undocumented |
Property | _clsregistry |
Undocumented |
Property | _effective |
Undocumented |
Property | _is |
Undocumented |
Property | _use |
memoize the 'use_get' attribute of this RelationshipLoader's lazyloader. |
Inherited from _IntrospectsAnnotations
:
Method | found |
return a copy of this object to use in declarative when the object is found inside of an Annotated object. |
Class Variable | __slots__ |
Undocumented |
Method | _raise |
Undocumented |
Inherited from StrategizedProperty
(via _IntrospectsAnnotations
):
Class Method | strategy |
Undocumented |
Method | create |
Produce row processing functions and append to the given set of populators lists. |
Method | post |
Perform instrumentation adjustments that need to occur after init() has completed. |
Method | setup |
Called by Query for the purposes of constructing a SQL statement. |
Class Variable | strategy |
Undocumented |
Instance Variable | strategy |
Undocumented |
Class Method | _strategy |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _memoized |
Undocumented |
Method | _memoized |
Undocumented |
Class Variable | _all |
Undocumented |
Instance Variable | _strategies |
Undocumented |
Inherited from MapperProperty
(via _IntrospectsAnnotations
, StrategizedProperty
):
Method | __repr__ |
Undocumented |
Method | init |
Called after all mappers are created to assemble relationships between mappers and perform other post-mapper-creation initialization steps. |
Method | set |
Set the parent mapper that references this MapperProperty. |
Class Variable | comparator |
The :class:`_orm.PropComparator` instance that implements SQL expression construction on behalf of this mapped attribute. |
Class Variable | info |
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.InspectionAttr`. |
Class Variable | is |
Part of the InspectionAttr interface; states this object is a mapper property. |
Class Variable | key |
name of class attribute |
Instance Variable | parent |
the :class:`.Mapper` managing this property. |
Property | class |
Return the class-bound descriptor corresponding to this :class:`.MapperProperty`. |
Method | _memoized |
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.InspectionAttr`. |
Class Variable | _cache |
Undocumented |
Instance Variable | _attribute |
behavioral options for ORM-enabled Python attributes |
Instance Variable | _configure |
Undocumented |
Instance Variable | _configure |
Undocumented |
Instance Variable | _has |
Undocumented |
Inherited from HasCacheKey
(via _IntrospectsAnnotations
, StrategizedProperty
, MapperProperty
):
Class Method | _generate |
generate cache key dispatcher for a new class. |
Class Method | _generate |
Undocumented |
Method | _gen |
return an optional cache key. |
Method | _generate |
return a cache key. |
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 TypingOnly
(via _IntrospectsAnnotations
, StrategizedProperty
, MapperProperty
, HasCacheKey
, _DCAttributeOptions
, _MappedAttribute
):
Method | __init |
Undocumented |
Inherited from InspectionAttr
(via _IntrospectsAnnotations
, StrategizedProperty
, MapperProperty
, HasCacheKey
, _DCAttributeOptions
, _MappedAttribute
, TypingOnly
, InspectionAttrInfo
):
Class Variable | is |
True if this object is an instance of :class:`.AliasedClass`. |
Class Variable | is |
True if this object is a Python :term:`descriptor`. |
Class Variable | is |
True if this object is an instance of :class:`.Bundle`. |
Class Variable | is |
True if this object is an instance of :class:`_expression.ClauseElement`. |
Class Variable | is |
True if this object is an instance of :class:`.InstanceState`. |
Class Variable | is |
True if this object is an instance of :class:`_orm.Mapper`. |
Class Variable | is |
Return True if this object is an instance of :class:`_expression.Selectable`. |
Class Variable | _is |
True if this object is an internal proxy object. |
Inherited from MemoizedSlots
(via _IntrospectsAnnotations
, StrategizedProperty
, MapperProperty
, HasCacheKey
, _DCAttributeOptions
, _MappedAttribute
, TypingOnly
, InspectionAttrInfo
, InspectionAttr
):
Method | __getattr__ |
Undocumented |
Method | _fallback |
Undocumented |
Inherited from Identified
(via _IntrospectsAnnotations
, StrategizedProperty
, MapperProperty
, HasCacheKey
, _DCAttributeOptions
, _MappedAttribute
, TypingOnly
, InspectionAttrInfo
, InspectionAttr
, MemoizedSlots
):
Class Variable | logger |
Undocumented |
Class Variable | logging |
Undocumented |
Method | _should |
Undocumented |
Method | _should |
Undocumented |
Class Variable | _echo |
Undocumented |
Optional[ _RelationshipArgumentType[ _T]]
= None, secondary: Optional[ _RelationshipSecondaryArgument]
= None, *, uselist: Optional[ bool]
= None, collection_class: Optional[ Union[ Type[ Collection[ Any]], Callable[ [], Collection[ Any]]]]
= None, primaryjoin: Optional[ _RelationshipJoinConditionArgument]
= None, secondaryjoin: Optional[ _RelationshipJoinConditionArgument]
= None, back_populates: Optional[ str]
= None, order_by: _ORMOrderByArgument
= False, backref: Optional[ ORMBackrefArgument]
= None, overlaps: Optional[ str]
= None, post_update: bool
= False, cascade: str
= 'save-update, merge', viewonly: bool
= False, attribute_options: Optional[ _AttributeOptions]
= None, lazy: _LazyLoadArgumentType
= 'select', passive_deletes: Union[ Literal[ 'all'], bool]
= False, passive_updates: bool
= True, active_history: bool
= False, enable_typechecks: bool
= True, foreign_keys: Optional[ _ORMColCollectionArgument]
= None, remote_side: Optional[ _ORMColCollectionArgument]
= None, join_depth: Optional[ int]
= None, comparator_factory: Optional[ Type[ RelationshipProperty.Comparator[ Any]]]
= None, single_parent: bool
= False, innerjoin: bool
= False, distinct_target_key: Optional[ bool]
= None, load_on_pending: bool
= False, query_class: Optional[ Type[ Query[ Any]]]
= None, info: Optional[ _InfoType]
= None, omit_join: Literal[ None, False]
= None, sync_backref: Optional[ bool]
= None, doc: Optional[ str]
= None, bake_queries: Literal[ True]
= True, cascade_backrefs: Literal[ False]
= False, _local_remote_pairs: Optional[ _ColumnPairs]
= None, _legacy_inactive_history_style: bool
= False):
(source)
¶
Undocumented
str
, state: InstanceState[ Any]
, dict_: _InstanceDict
, visited_states: Set[ InstanceState[ Any]]
, halt_on: Optional[ Callable[ [ InstanceState[ Any]], bool]]
= None) -> Iterator[ Tuple[ Any, Mapper[ Any], InstanceState[ Any], _InstanceDict]]
:
(source)
¶
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 Relationship.
_ClassScanMapperConfig
, registry: _RegistryType
, cls: Type[ Any]
, originating_module: Optional[ str]
, key: str
, mapped_container: Optional[ Type[ Mapped[ Any]]]
, annotation: Optional[ _AnnotationScanType]
, extracted_mapped_annotation: Optional[ _AnnotationScanType]
, is_dataclass_field: bool
):
(source)
¶
Perform class-specific initializaton at early declarative scanning time. .. versionadded:: 2.0
Perform subclass-specific initialization post-mapper-creation steps. This is a template method called by the ``MapperProperty`` object's init() method.
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).
Session
, source_state: InstanceState[ Any]
, source_dict: _InstanceDict
, dest_state: InstanceState[ Any]
, dest_dict: _InstanceDict
, load: bool
, _recursive: Dict[ Any, object]
, _resolve_conflict_map: Dict[ _IdentityKeyType[ Any], object]
):
(source)
¶
Merge the attribute represented by this ``MapperProperty`` from source to destination object.
Return the target mapped entity, which is an inspect() of the class or aliased class that is referred towards.
def _check_sync_backref(rel_a:
RelationshipProperty[ Any]
, rel_b: RelationshipProperty[ Any]
):
(source)
¶
Undocumented
Return True if all columns in the given collection are mapped by the tables referenced by this :class:`.RelationshipProperty`.
bool
= False, source_selectable: Optional[ FromClause]
= None, dest_selectable: Optional[ FromClause]
= None, of_type_entity: Optional[ _InternalEntityType[ Any]]
= None, alias_secondary: bool
= False, extra_criteria: Tuple[ ColumnElement[ bool], ...]
= ()) -> Tuple[ ColumnElement[ bool], Optional[ ColumnElement[ bool]], FromClause, FromClause, Optional[ FromClause], Optional[ ClauseAdapter]]
:
(source)
¶
Undocumented
Interpret the 'backref' instruction to create a :func:`_orm.relationship` complementary to this one.
Mapper[ Any]
, state: InstanceState[ Any]
, dict_: _InstanceDict
, column: ColumnElement[ Any]
) -> Callable[ [], Any]
:
(source)
¶
Create the callable that is used in a many-to-one expression. E.g.:: u1 = s.query(User).get(5) expr = Address.user == u1 Above, the SQL should be "address.user_id = 5". The callable returned by this method produces the value "5" based on the identity of ``u1``.
bool
= False, adapt_source: Optional[ _CoreAdapterProto]
= None) -> ColumnElement[ bool]
:
(source)
¶
Undocumented
Any
, value_is_parent: bool
= False, adapt_source: Optional[ _CoreAdapterProto]
= None, alias_secondary: bool
= True) -> ColumnElement[ bool]
:
(source)
¶
Undocumented
Convert incoming configuration arguments to their proper form. Callables are resolved, ORM annotations removed.
def _setup_entity(self, __argument:
Any
= None):
(source)
¶
Undocumented
InstanceState[ _O]
, dict_: _InstanceDict
, key: str
, passive: PassiveFlag
= PassiveFlag.PASSIVE_OFF) -> Sequence[ Tuple[ InstanceState[ _O], _O]]
:
(source)
¶
Return a list of tuples (state, obj) for the given key. returns an empty list if the value is None/empty/PASSIVE_NO_RESULT
object
, alias_secondary: bool
= True, from_entity: Optional[ _EntityType[ Any]]
= None) -> ColumnElement[ bool]
:
(source)
¶
Undocumented
True if this MapperProperty refers to a mapped entity. Should only be True for Relationship, False for all others.
_clsregistry_resolve_name:
Callable[ [ str], Callable[ [], Union[ Type[ Any], Table, _ModNS]]]
=
(source)
¶
Undocumented