class documentation

class AssociationProxy(interfaces.InspectionAttrInfo):

View In Hierarchy

A descriptor that presents a read/write view of an object attribute.
Method __init__ Construct a new .AssociationProxy.
Method for​_class Return the internal state local to a specific mapped class.
Class Variable is​_attribute True if this object is a Python :term:`descriptor`.
Instance Variable info Info dictionary associated with the object, allowing user-defined data to be associated with this .InspectionAttr.
Method __delete__ Undocumented
Method __get__ Undocumented
Method __repr__ Undocumented
Method __set__ Undocumented
Method ​_as​_instance Undocumented
Method ​_calc​_owner Undocumented
Method ​_default​_getset Undocumented
Instance Variable cascade​_scalar​_deletes Undocumented
Instance Variable creator Undocumented
Instance Variable getset​_factory Undocumented
Instance Variable key Undocumented
Instance Variable proxy​_bulk​_set Undocumented
Instance Variable proxy​_factory Undocumented
Instance Variable target​_collection Undocumented
Instance Variable value​_attr Undocumented

Inherited from InspectionAttr (via InspectionAttrInfo):

Class Variable __slots__ Undocumented
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​_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​_property True if this object is an instance of .MapperProperty.
Class Variable is​_selectable Return True if this object is an instance of _expression.Selectable.
def __init__(self, target_collection, attr, creator=None, getset_factory=None, proxy_factory=None, proxy_bulk_set=None, info=None, cascade_scalar_deletes=False):

Construct a new .AssociationProxy.

The .association_proxy function is provided as the usual entrypoint here, though .AssociationProxy can be instantiated and/or subclassed directly.

Parameters
target​_collectionName of the collection we'll proxy to, usually created with _orm.relationship.
attrAttribute on the collected instances we'll proxy for. For example, given a target collection of [obj1, obj2], a list created by this proxy property would look like [getattr(obj1, attr), getattr(obj2, attr)]
creator

Optional. When new items are added to this proxied collection, new instances of the class collected by the target collection will be created. For list and set collections, the target class constructor will be called with the 'value' for the new instance. For dict types, two arguments are passed: key and value.

If you want to construct instances differently, supply a 'creator' function that takes arguments as above and returns instances.

getset​_factory

Optional. Proxied attribute access is automatically handled by routines that get and set values based on the attr argument for this proxy.

If you would like to customize this behavior, you may supply a getset_factory callable that produces a tuple of getter and setter functions. The factory is called with two arguments, the abstract type of the underlying collection and this proxy instance.

proxy​_factoryOptional. The type of collection to emulate is determined by sniffing the target collection. If your collection type can't be determined by duck typing or you'd like to use a different collection implementation, you may supply a factory function to produce those collections. Only applicable to non-scalar relationships.
proxy​_bulk​_setOptional, use with proxy_factory. See the _set() method for details.
info

optional, will be assigned to .AssociationProxy.info if present.

New in version 1.0.9.
cascade​_scalar​_deletes

when True, indicates that setting the proxied value to None, or deleting it via del, should also remove the source object. Only applies to scalar attributes. Normally, removing the proxied target will not remove the proxy source, as this object may have other state that is still to be kept.

New in version 1.3.

See Also

:ref:`cascade_scalar_deletes` - complete usage example

def for_class(self, class_, obj=None):

Return the internal state local to a specific mapped class.

E.g., given a class User:

class User(Base):
    # ...

    keywords = association_proxy('kws', 'keyword')

If we access this .AssociationProxy from _orm.Mapper.all_orm_descriptors, and we want to view the target class for this proxy as mapped by User:

inspect(User).all_orm_descriptors["keywords"].for_class(User).target_class

This returns an instance of .AssociationProxyInstance that is specific to the User class. The .AssociationProxy object remains agnostic of its parent class.

New in version 1.3: - .AssociationProxy no longer stores any state specific to a particular parent class; the state is now stored in per-class .AssociationProxyInstance objects.
Parameters
class​_the class that we are returning state for.
objoptional, an instance of the class that is required if the attribute refers to a polymorphic target, e.g. where we have to look at the type of the actual destination object to get the complete path.
is_attribute: bool =

True if this object is a Python :term:`descriptor`.

This can refer to one of many types. Usually a .QueryableAttribute which handles attributes events on behalf of a .MapperProperty. But can also be an extension type such as .AssociationProxy or .hybrid_property. The .InspectionAttr.extension_type will refer to a constant identifying the specific subtype.

See Also

_orm.Mapper.all_orm_descriptors

info =

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 __delete__(self, obj):

Undocumented

def __get__(self, obj, class_):

Undocumented

def __repr__(self):

Undocumented

def __set__(self, obj, values):

Undocumented

def _as_instance(self, class_, obj):

Undocumented

def _calc_owner(self, target_cls):

Undocumented

def _default_getset(self, collection_class):

Undocumented

cascade_scalar_deletes =

Undocumented

creator =

Undocumented

getset_factory =

Undocumented

key =

Undocumented

proxy_bulk_set =

Undocumented

proxy_factory =

Undocumented

target_collection =

Undocumented

value_attr =

Undocumented