module documentation

Contain the AssociationProxy class.

The AssociationProxy is a Python property object which provides transparent proxied access to the endpoint of an association object.

See the example examples/association/proxied_association.py.

Class ​Association​Proxy A descriptor that presents a read/write view of an object attribute.
Class ​Association​Proxy​Instance A per-class object that serves class- and object-specific results.
Class ​Column​Association​Proxy​Instance an .AssociationProxyInstance that has a database column as a target.
Class ​Object​Association​Proxy​Instance an .AssociationProxyInstance that has an object as a target.
Function association​_proxy Return a Python property implementing a view of a target attribute which references an attribute on members of the target.
Constant ASSOCIATION​_PROXY Symbol indicating an .InspectionAttr that's of type .AssociationProxy.
Class _​Association​Collection No class docstring; 0/5 instance variable, 0/1 class variable, 1/6 method documented
Class _​Association​Dict Generic, converting, dict-to-dict proxy.
Class _​Association​List Generic, converting, list-to-list proxy.
Class _​Association​Set Generic, converting, set-to-set proxy.
Class ​_lazy​_collection Undocumented
Class ​Ambiguous​Association​Proxy​Instance an .AssociationProxyInstance where we cannot determine the type of target object.
Variable _​Not​Provided Undocumented
def association_proxy(target_collection, attr, **kw):

Return a Python property implementing a view of a target attribute which references an attribute on members of the target.

The returned value is an instance of .AssociationProxy.

Implements a Python property representing a relationship as a collection of simpler values, or a scalar value. The proxied property will mimic the collection type of the target (list, dict or set), or, in the case of a one to one relationship, a simple scalar value.

Parameters
target​_collectionName of the attribute we'll proxy to. This attribute is typically mapped by ~sqlalchemy.orm.relationship to link to a target collection, but can also be a many-to-one or non-scalar relationship.
attr

Attribute on the associated instance or 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)]

If the relationship is one-to-one or otherwise uselist=False, then simply: getattr(obj, attr)

**kwPasses along any other keyword arguments to .AssociationProxy.
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.

For scalar relationships, creator() will be called if the target is None. If the target is present, set operations are proxied to setattr() on the associated object.

If you have an associated object with multiple attributes, you may set up multiple association proxies mapping to different attributes. See the unit tests for examples, and for examples of how creator() functions can be used to construct the scalar relationship on-demand in this situation.

ASSOCIATION_PROXY =
Symbol indicating an .InspectionAttr that's
of type .AssociationProxy.

Is assigned to the .InspectionAttr.extension_type attribute.

Value
util.symbol('ASSOCIATION_PROXY')
_NotProvided =

Undocumented