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

Class Load

lib/sqlalchemy/orm/strategy_options.py:969–1334  ·  view source on GitHub ↗

Represents loader options which modify the state of a ORM-enabled :class:`_sql.Select` or a legacy :class:`_query.Query` in order to affect how various mapped attributes are loaded. The :class:`_orm.Load` object is in most cases used implicitly behind the scenes when one makes use o

Source from the content-addressed store, hash-verified

967
968
969class Load(_AbstractLoad):
970 """Represents loader options which modify the state of a
971 ORM-enabled :class:`_sql.Select` or a legacy :class:`_query.Query` in
972 order to affect how various mapped attributes are loaded.
973
974 The :class:`_orm.Load` object is in most cases used implicitly behind the
975 scenes when one makes use of a query option like :func:`_orm.joinedload`,
976 :func:`_orm.defer`, or similar. It typically is not instantiated directly
977 except for in some very specific cases.
978
979 .. seealso::
980
981 :ref:`orm_queryguide_relationship_per_entity_wildcard` - illustrates an
982 example where direct use of :class:`_orm.Load` may be useful
983
984 """
985
986 __slots__ = (
987 "path",
988 "context",
989 "additional_source_entities",
990 )
991
992 _traverse_internals = [
993 ("path", visitors.ExtendedInternalTraversal.dp_has_cache_key),
994 (
995 "context",
996 visitors.InternalTraversal.dp_has_cache_key_list,
997 ),
998 ("propagate_to_loaders", visitors.InternalTraversal.dp_boolean),
999 (
1000 "additional_source_entities",
1001 visitors.InternalTraversal.dp_has_cache_key_list,
1002 ),
1003 ]
1004 _cache_key_traversal = None
1005
1006 path: PathRegistry
1007 context: Tuple[_LoadElement, ...]
1008 additional_source_entities: Tuple[_InternalEntityType[Any], ...]
1009
1010 def __init__(self, entity: _EntityType[Any]):
1011 insp = cast("Union[Mapper[Any], AliasedInsp[Any]]", inspect(entity))
1012 insp._post_inspect
1013
1014 self.path = insp._path_registry
1015 self.context = ()
1016 self.propagate_to_loaders = False
1017 self.additional_source_entities = ()
1018
1019 def __str__(self) -> str:
1020 return f"Load({self.path[0]})"
1021
1022 @classmethod
1023 def _construct_for_existing_path(
1024 cls, path: AbstractEntityRegistry
1025 ) -> Load:
1026 load = cls.__new__(cls)

Calls

no outgoing calls