class AssociationProxy(interfaces.InspectionAttrInfo):
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 . |
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_collection | Name of the collection we'll proxy to,
usually created with _orm.relationship . |
attr | Attribute 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 If you would like to customize this behavior, you may supply a
|
proxy_factory | Optional. 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_set | Optional, use with proxy_factory. See the _set() method for details. |
info | optional, will be assigned to
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 |
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.
.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. |
obj | optional, 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. |
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 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.
.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