MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / init_collection

Method init_collection

lib/sqlalchemy/orm/events.py:2948–2989  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

2946 """ # noqa: E501
2947
2948 def init_collection(
2949 self,
2950 target: _O,
2951 collection: Type[Collection[Any]],
2952 collection_adapter: CollectionAdapter,
2953 ) -> None:
2954 """Receive a 'collection init' event.
2955
2956 This event is triggered for a collection-based attribute, when
2957 the initial "empty collection" is first generated for a blank
2958 attribute, as well as for when the collection is replaced with
2959 a new one, such as via a set event.
2960
2961 E.g., given that ``User.addresses`` is a relationship-based
2962 collection, the event is triggered here::
2963
2964 u1 = User()
2965 u1.addresses.append(a1) # <- new collection
2966
2967 and also during replace operations::
2968
2969 u1.addresses = [a2, a3] # <- new collection
2970
2971 :param target: the object instance receiving the event.
2972 If the listener is registered with ``raw=True``, this will
2973 be the :class:`.InstanceState` object.
2974 :param collection: the new collection. This will always be generated
2975 from what was specified as
2976 :paramref:`_orm.relationship.collection_class`, and will always
2977 be empty.
2978 :param collection_adapter: the :class:`.CollectionAdapter` that will
2979 mediate internal access to the collection.
2980
2981 .. seealso::
2982
2983 :class:`.AttributeEvents` - background on listener options such
2984 as propagation to subclasses.
2985
2986 :meth:`.AttributeEvents.init_scalar` - "scalar" version of this
2987 event.
2988
2989 """
2990
2991 def dispose_collection(
2992 self,

Callers 4

test_helpersMethod · 0.80

Calls

no outgoing calls

Tested by 3

test_helpersMethod · 0.64