MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _apply_to_parent

Method _apply_to_parent

lib/sqlalchemy/orm/strategy_options.py:1152–1189  ·  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

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