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

Method _apply_to_parent

lib/sqlalchemy/orm/strategy_options.py:1150–1187  ·  view source on GitHub ↗

apply this :class:`_orm.Load` object as a sub-option of another :class:`_orm.Load` object. This method is used by the :meth:`_orm.Load.options` method.

(self, parent: Load)

Source from the content-addressed store, hash-verified

1148 )
1149
1150 def _apply_to_parent(self, parent: Load) -> None:
1151 """apply this :class:`_orm.Load` object as a sub-option of another
1152 :class:`_orm.Load` object.
1153
1154 This method is used by the :meth:`_orm.Load.options` method.
1155
1156 """
1157 cloned = self._generate()
1158
1159 assert cloned.propagate_to_loaders == self.propagate_to_loaders
1160
1161 if not any(
1162 orm_util._entity_corresponds_to_use_path_impl(
1163 elem, cloned.path.odd_element(0)
1164 )
1165 for elem in (parent.path.odd_element(-1),)
1166 + parent.additional_source_entities
1167 ):
1168 if len(cloned.path) > 1:
1169 attrname = cloned.path[1]
1170 parent_entity = cloned.path[0]
1171 else:
1172 attrname = cloned.path[0]
1173 parent_entity = cloned.path[0]
1174 _raise_for_does_not_link(parent.path, attrname, parent_entity)
1175
1176 cloned.path = PathRegistry.coerce(parent.path[0:-1] + cloned.path[:])
1177
1178 if self.context:
1179 cloned.context = tuple(
1180 value._prepend_path_from(parent) for value in self.context
1181 )
1182
1183 if cloned.context:
1184 parent.context += cloned.context
1185 parent.additional_source_entities += (
1186 cloned.additional_source_entities
1187 )
1188
1189 @_generative
1190 def options(self, *opts: _AbstractLoad) -> Self:

Callers 1

optionsMethod · 0.45

Calls 5

_raise_for_does_not_linkFunction · 0.85
odd_elementMethod · 0.80
_prepend_path_fromMethod · 0.80
_generateMethod · 0.45
coerceMethod · 0.45

Tested by

no test coverage detected