MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / options

Method options

lib/sqlalchemy/orm/strategy_options.py:1192–1229  ·  view source on GitHub ↗

r"""Apply a series of options as sub-options to this :class:`_orm.Load` object. E.g.:: query = session.query(Author) query = query.options( joinedload(Author.book).options( load_only(Book.summary, Book.excerpt),

(self, *opts: _AbstractLoad)

Source from the content-addressed store, hash-verified

1190
1191 @_generative
1192 def options(self, *opts: _AbstractLoad) -> Self:
1193 r"""Apply a series of options as sub-options to this
1194 :class:`_orm.Load`
1195 object.
1196
1197 E.g.::
1198
1199 query = session.query(Author)
1200 query = query.options(
1201 joinedload(Author.book).options(
1202 load_only(Book.summary, Book.excerpt),
1203 joinedload(Book.citations).options(joinedload(Citation.author)),
1204 )
1205 )
1206
1207 :param \*opts: A series of loader option objects (ultimately
1208 :class:`_orm.Load` objects) which should be applied to the path
1209 specified by this :class:`_orm.Load` object.
1210
1211 .. seealso::
1212
1213 :func:`.defaultload`
1214
1215 :ref:`orm_queryguide_relationship_sub_options`
1216
1217 """
1218 for opt in opts:
1219 try:
1220 opt._apply_to_parent(self)
1221 except AttributeError as ae:
1222 if not isinstance(opt, _AbstractLoad):
1223 raise sa_exc.ArgumentError(
1224 f"Loader option {opt} is not compatible with the "
1225 "Load.options() method."
1226 ) from ae
1227 else:
1228 raise
1229 return self
1230
1231 def _clone_for_bind_strategy(
1232 self,

Callers

nothing calls this directly

Calls 1

_apply_to_parentMethod · 0.45

Tested by

no test coverage detected