A descriptor that presents a read/write view of an object attribute.
| 362 | |
| 363 | |
| 364 | class AssociationProxy( |
| 365 | interfaces.InspectionAttrInfo, |
| 366 | ORMDescriptor[_T], |
| 367 | _DCAttributeOptions, |
| 368 | _AssociationProxyProtocol[_T], |
| 369 | ): |
| 370 | """A descriptor that presents a read/write view of an object attribute.""" |
| 371 | |
| 372 | is_attribute = True |
| 373 | extension_type = AssociationProxyExtensionType.ASSOCIATION_PROXY |
| 374 | |
| 375 | def __init__( |
| 376 | self, |
| 377 | target_collection: str, |
| 378 | attr: str, |
| 379 | *, |
| 380 | creator: Optional[_CreatorProtocol] = None, |
| 381 | getset_factory: Optional[_GetSetFactoryProtocol] = None, |
| 382 | proxy_factory: Optional[_ProxyFactoryProtocol] = None, |
| 383 | proxy_bulk_set: Optional[_ProxyBulkSetProtocol] = None, |
| 384 | info: Optional[_InfoType] = None, |
| 385 | cascade_scalar_deletes: bool = False, |
| 386 | create_on_none_assignment: bool = False, |
| 387 | attribute_options: Optional[_AttributeOptions] = None, |
| 388 | ): |
| 389 | """Construct a new :class:`.AssociationProxy`. |
| 390 | |
| 391 | The :class:`.AssociationProxy` object is typically constructed using |
| 392 | the :func:`.association_proxy` constructor function. See the |
| 393 | description of :func:`.association_proxy` for a description of all |
| 394 | parameters. |
| 395 | |
| 396 | |
| 397 | """ |
| 398 | self.target_collection = target_collection |
| 399 | self.value_attr = attr |
| 400 | self.creator = creator |
| 401 | self.getset_factory = getset_factory |
| 402 | self.proxy_factory = proxy_factory |
| 403 | self.proxy_bulk_set = proxy_bulk_set |
| 404 | |
| 405 | if cascade_scalar_deletes and create_on_none_assignment: |
| 406 | raise exc.ArgumentError( |
| 407 | "The cascade_scalar_deletes and create_on_none_assignment " |
| 408 | "parameters are mutually exclusive." |
| 409 | ) |
| 410 | self.cascade_scalar_deletes = cascade_scalar_deletes |
| 411 | self.create_on_none_assignment = create_on_none_assignment |
| 412 | |
| 413 | self.key = "_%s_%s_%s" % ( |
| 414 | type(self).__name__, |
| 415 | target_collection, |
| 416 | id(self), |
| 417 | ) |
| 418 | if info: |
| 419 | self.info = info # type: ignore |
| 420 | |
| 421 | if ( |