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