class documentation

class Load(Generative, LoaderOption):

Known subclasses: sqlalchemy.orm.strategy_options._UnboundLoad

View In Hierarchy

Represents loader options which modify the state of a _query.Query in order to affect how various mapped attributes are loaded.

The _orm.Load object is in most cases used implicitly behind the scenes when one makes use of a query option like _orm.joinedload, .defer, or similar. However, the _orm.Load object can also be used directly, and in some cases can be useful.

To use _orm.Load directly, instantiate it with the target mapped class as the argument. This style of usage is useful when dealing with a _query.Query that has multiple entities:

myopt = Load(MyClass).joinedload("widgets")

The above myopt can now be used with _query.Query.options, where it will only take effect for the MyClass entity:

session.query(MyClass, MyOtherClass).options(myopt)

One case where _orm.Load is useful as public API is when specifying "wildcard" options that only take effect for a certain class:

session.query(Order).options(Load(Order).lazyload('*'))

Above, all relationships on Order will be lazy-loaded, but other attributes on those descendant objects will load using their normal loader strategy.

Class Method for​_existing​_path Undocumented
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __setstate__ Undocumented
Method __str__ Undocumented
Method ​_adjust​_for​_extra​_criteria Apply the current bound parameters in a QueryContext to all occurrences "extra_criteria" stored within al this Load object; copying in place.
Method ​_apply​_to​_parent Undocumented
Method ​_chop​_path Undocumented
Method ​_clone​_for​_bind​_strategy No summary
Method ​_coerce​_strat Undocumented
Method ​_deep​_clone Undocumented
Method ​_generate Undocumented
Method ​_generate​_extra​_criteria Apply the current bound parameters in a QueryContext to the immediate "extra_criteria" stored with this Load object.
Method ​_generate​_path Undocumented
Method ​_process Undocumented
Method ​_set​_for​_path Undocumented
Method ​_set​_path​_strategy Undocumented
Method options Apply a series of options as sub-options to this _orm.Load object.
Method process​_compile​_state Apply a modification to a given .CompileState.
Method process​_compile​_state​_replaced​_entities Apply a modification to a given .CompileState, given entities that were replaced by with_only_columns() or with_entities().
Method set​_class​_strategy Undocumented
Method set​_column​_strategy Undocumented
Method set​_generic​_strategy Undocumented
Method set​_relationship​_strategy Undocumented
Class Variable ​_cache​_key​_traversal Undocumented
Class Variable ​_is​_strategy​_option Undocumented
Class Variable is​_opts​_only Undocumented
Class Variable strategy Undocumented
Instance Variable ​_extra​_criteria Undocumented
Instance Variable ​_of​_type Undocumented
Instance Variable context Undocumented
Instance Variable is​_class​_strategy Undocumented
Instance Variable local​_opts Undocumented
Instance Variable path Undocumented
Instance Variable propagate​_to​_loaders if True, indicate this option should be carried along to "secondary" SELECT statements that occur for relationship lazy loaders as well as attribute load / refresh operations.
Property ​_context​_cache​_key Undocumented

Inherited from CompileStateOption (via LoaderOption):

Class Variable ​_is​_compile​_state Undocumented

Inherited from HasCacheKey (via LoaderOption, CompileStateOption):

Class Variable inherit​_cache Indicate if this .HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.
Class Method ​_generate​_cache​_attrs generate cache key dispatcher for a new class.
Class Method ​_generate​_cache​_key​_for​_object Undocumented
Method ​_gen​_cache​_key return an optional cache key.
Method ​_generate​_cache​_key return a cache key.
Class Variable __slots__ Undocumented
Class Variable ​_hierarchy​_supports​_caching private attribute which may be set to False to prevent the inherit_cache warning from being emitted for a hierarchy of subclasses.
Class Variable ​_is​_has​_cache​_key Undocumented

Inherited from ORMOption (via LoaderOption, CompileStateOption):

Class Variable __slots__ Undocumented
Class Variable ​_is​_criteria​_option Undocumented
Class Variable ​_is​_legacy​_option Undocumented

Inherited from ExecutableOption (via LoaderOption, CompileStateOption, ORMOption):

Method ​_clone Create a shallow copy of this ExecutableOption.
Class Variable __visit​_name__ Undocumented
Class Variable ​_is​_has​_cache​_key Undocumented

Inherited from HasCopyInternals (via LoaderOption, CompileStateOption, ORMOption, ExecutableOption):

Method ​_copy​_internals Reassign internal elements to be clones of themselves.
@classmethod
def for_existing_path(cls, path):

Undocumented

def __getstate__(self):
def __init__(self, entity):
def __setstate__(self, state):
def __str__(self):

Undocumented

def _adjust_for_extra_criteria(self, context):
Apply the current bound parameters in a QueryContext to all occurrences "extra_criteria" stored within al this Load object; copying in place.
def _apply_to_parent(self, parent, applied, bound):
def _chop_path(self, to_chop, path):
def _clone_for_bind_strategy(self, attr, strategy, wildcard_key, opts_only=False, opts=None):
Create an anonymous clone of the Load/_UnboundLoad that is suitable to be placed in the context / _to_bind collection of this Load object. The clone will then lose references to context/_to_bind in order to not create reference cycles.
def _coerce_strat(self, strategy):

Undocumented

def _deep_clone(self, applied, process):
def _generate(self):
def _generate_extra_criteria(self, context):

Apply the current bound parameters in a QueryContext to the immediate "extra_criteria" stored with this Load object.

Load objects are typically pulled from the cached version of the statement from a QueryContext. The statement currently being executed will have new values (and keys) for bound parameters in the extra criteria which need to be applied by loader strategies when they handle this criteria for a result set.

def _generate_path(self, path, attr, for_strategy, wildcard_key, raiseerr=True, polymorphic_entity_context=None):
def _process(self, compile_state, mapper_entities, raiseerr):
def _set_for_path(self, context, path, replace=True, merge_opts=False):

Undocumented

def _set_path_strategy(self):
@_generative
def options(self, *opts):

Apply a series of options as sub-options to this _orm.Load object.

E.g.:

query = session.query(Author)
query = query.options(
            joinedload(Author.book).options(
                load_only(Book.summary, Book.excerpt),
                joinedload(Book.citations).options(
                    joinedload(Citation.author)
                )
            )
        )
New in version 1.3.6.
Parameters
*optsA series of loader option objects (ultimately _orm.Load objects) which should be applied to the path specified by this _orm.Load object.
def process_compile_state(self, compile_state):
Apply a modification to a given .CompileState.
def process_compile_state_replaced_entities(self, compile_state, mapper_entities):

Apply a modification to a given .CompileState, given entities that were replaced by with_only_columns() or with_entities().

New in version 1.4.19.
@_generative
def set_class_strategy(self, strategy, opts):

Undocumented

@_generative
def set_column_strategy(self, attrs, strategy, opts=None, opts_only=False):

Undocumented

@_generative
def set_generic_strategy(self, attrs, strategy):

Undocumented

@_generative
def set_relationship_strategy(self, attr, strategy, propagate_to_loaders=True):

Undocumented

_cache_key_traversal =

Undocumented

_is_strategy_option: bool =
is_opts_only: bool =

Undocumented

strategy =

Undocumented

_extra_criteria =
_of_type =

Undocumented

context =

Undocumented

is_class_strategy: bool =

Undocumented

local_opts: dict =
path =
propagate_to_loaders =
if True, indicate this option should be carried along to "secondary" SELECT statements that occur for relationship lazy loaders as well as attribute load / refresh operations.
@property
_context_cache_key =

Undocumented