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)
| 2695 | |
| 2696 | |
| 2697 | def 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 | |
| 2720 | def init_state_collection( |
nothing calls this directly
no test coverage detected