Receive a 'collection init' event. This event is triggered for a collection-based attribute, when the initial "empty collection" is first generated for a blank attribute, as well as for when the collection is replaced with a new one, such as via a set event.
(
self,
target: _O,
collection: Type[Collection[Any]],
collection_adapter: CollectionAdapter,
)
| 2913 | """ # noqa: E501 |
| 2914 | |
| 2915 | def init_collection( |
| 2916 | self, |
| 2917 | target: _O, |
| 2918 | collection: Type[Collection[Any]], |
| 2919 | collection_adapter: CollectionAdapter, |
| 2920 | ) -> None: |
| 2921 | """Receive a 'collection init' event. |
| 2922 | |
| 2923 | This event is triggered for a collection-based attribute, when |
| 2924 | the initial "empty collection" is first generated for a blank |
| 2925 | attribute, as well as for when the collection is replaced with |
| 2926 | a new one, such as via a set event. |
| 2927 | |
| 2928 | E.g., given that ``User.addresses`` is a relationship-based |
| 2929 | collection, the event is triggered here:: |
| 2930 | |
| 2931 | u1 = User() |
| 2932 | u1.addresses.append(a1) # <- new collection |
| 2933 | |
| 2934 | and also during replace operations:: |
| 2935 | |
| 2936 | u1.addresses = [a2, a3] # <- new collection |
| 2937 | |
| 2938 | :param target: the object instance receiving the event. |
| 2939 | If the listener is registered with ``raw=True``, this will |
| 2940 | be the :class:`.InstanceState` object. |
| 2941 | :param collection: the new collection. This will always be generated |
| 2942 | from what was specified as |
| 2943 | :paramref:`_orm.relationship.collection_class`, and will always |
| 2944 | be empty. |
| 2945 | :param collection_adapter: the :class:`.CollectionAdapter` that will |
| 2946 | mediate internal access to the collection. |
| 2947 | |
| 2948 | .. seealso:: |
| 2949 | |
| 2950 | :class:`.AttributeEvents` - background on listener options such |
| 2951 | as propagation to subclasses. |
| 2952 | |
| 2953 | :meth:`.AttributeEvents.init_scalar` - "scalar" version of this |
| 2954 | event. |
| 2955 | |
| 2956 | """ |
| 2957 | |
| 2958 | def dispose_collection( |
| 2959 | self, |
no outgoing calls