r"""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 :class:`.AssociationProxy`. Implements a Python property representing a relationship as a collection of simpler va
(
target_collection: str,
attr: str,
*,
creator: Optional[_CreatorProtocol] = None,
getset_factory: Optional[_GetSetFactoryProtocol] = None,
proxy_factory: Optional[_ProxyFactoryProtocol] = None,
proxy_bulk_set: Optional[_ProxyBulkSetProtocol] = None,
info: Optional[_InfoType] = None,
cascade_scalar_deletes: bool = False,
create_on_none_assignment: bool = False,
init: Union[_NoArg, bool] = _NoArg.NO_ARG,
repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002
default: Optional[Any] = _NoArg.NO_ARG,
default_factory: Union[_NoArg, Callable[[], _T]] = _NoArg.NO_ARG,
compare: Union[_NoArg, bool] = _NoArg.NO_ARG,
kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG,
hash: Union[_NoArg, bool, None] = _NoArg.NO_ARG, # noqa: A002
dataclass_metadata: Union[_NoArg, Mapping[Any, Any], None] = _NoArg.NO_ARG,
)
| 83 | |
| 84 | |
| 85 | def association_proxy( |
| 86 | target_collection: str, |
| 87 | attr: str, |
| 88 | *, |
| 89 | creator: Optional[_CreatorProtocol] = None, |
| 90 | getset_factory: Optional[_GetSetFactoryProtocol] = None, |
| 91 | proxy_factory: Optional[_ProxyFactoryProtocol] = None, |
| 92 | proxy_bulk_set: Optional[_ProxyBulkSetProtocol] = None, |
| 93 | info: Optional[_InfoType] = None, |
| 94 | cascade_scalar_deletes: bool = False, |
| 95 | create_on_none_assignment: bool = False, |
| 96 | init: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 97 | repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002 |
| 98 | default: Optional[Any] = _NoArg.NO_ARG, |
| 99 | default_factory: Union[_NoArg, Callable[[], _T]] = _NoArg.NO_ARG, |
| 100 | compare: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 101 | kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 102 | hash: Union[_NoArg, bool, None] = _NoArg.NO_ARG, # noqa: A002 |
| 103 | dataclass_metadata: Union[_NoArg, Mapping[Any, Any], None] = _NoArg.NO_ARG, |
| 104 | ) -> AssociationProxy[Any]: |
| 105 | r"""Return a Python property implementing a view of a target |
| 106 | attribute which references an attribute on members of the |
| 107 | target. |
| 108 | |
| 109 | The returned value is an instance of :class:`.AssociationProxy`. |
| 110 | |
| 111 | Implements a Python property representing a relationship as a collection |
| 112 | of simpler values, or a scalar value. The proxied property will mimic |
| 113 | the collection type of the target (list, dict or set), or, in the case of |
| 114 | a one to one relationship, a simple scalar value. |
| 115 | |
| 116 | :param target_collection: Name of the attribute that is the immediate |
| 117 | target. This attribute is typically mapped by |
| 118 | :func:`~sqlalchemy.orm.relationship` to link to a target collection, but |
| 119 | can also be a many-to-one or non-scalar relationship. |
| 120 | |
| 121 | :param attr: Attribute on the associated instance or instances that |
| 122 | are available on instances of the target object. |
| 123 | |
| 124 | :param creator: optional. |
| 125 | |
| 126 | Defines custom behavior when new items are added to the proxied |
| 127 | collection. |
| 128 | |
| 129 | By default, adding new items to the collection will trigger a |
| 130 | construction of an instance of the target object, passing the given |
| 131 | item as a positional argument to the target constructor. For cases |
| 132 | where this isn't sufficient, :paramref:`.association_proxy.creator` |
| 133 | can supply a callable that will construct the object in the |
| 134 | appropriate way, given the item that was passed. |
| 135 | |
| 136 | For list- and set- oriented collections, a single argument is |
| 137 | passed to the callable. For dictionary oriented collections, two |
| 138 | arguments are passed, corresponding to the key and value. |
| 139 | |
| 140 | The :paramref:`.association_proxy.creator` callable is also invoked |
| 141 | for scalar (i.e. many-to-one, one-to-one) relationships. If the |
| 142 | current value of the target relationship attribute is ``None``, the |