MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / init_collection

Function init_collection

lib/sqlalchemy/orm/attributes.py:2697–2717  ·  view source on GitHub ↗

Initialize a collection attribute and return the collection adapter. This function is used to provide direct access to collection internals for a previously unloaded attribute. e.g.:: collection_adapter = init_collection(someobject, "elements") for elem in values:

(obj: object, key: str)

Source from the content-addressed store, hash-verified

2695
2696
2697def init_collection(obj: object, key: str) -> CollectionAdapter:
2698 """Initialize a collection attribute and return the collection adapter.
2699
2700 This function is used to provide direct access to collection internals
2701 for a previously unloaded attribute. e.g.::
2702
2703 collection_adapter = init_collection(someobject, "elements")
2704 for elem in values:
2705 collection_adapter.append_without_event(elem)
2706
2707 For an easier way to do the above, see
2708 :func:`~sqlalchemy.orm.attributes.set_committed_value`.
2709
2710 :param obj: a mapped object
2711
2712 :param key: string attribute name where the collection is located.
2713
2714 """
2715 state = instance_state(obj)
2716 dict_ = state.dict
2717 return init_state_collection(state, dict_, key)
2718
2719
2720def init_state_collection(

Callers

nothing calls this directly

Calls 2

instance_stateFunction · 0.85
init_state_collectionFunction · 0.85

Tested by

no test coverage detected