diff options
Diffstat (limited to 'lib/sqlalchemy/orm/strategy_options.py')
-rw-r--r-- | lib/sqlalchemy/orm/strategy_options.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index cb7a5fef7..5b2a190b9 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -854,6 +854,29 @@ def noload(*keys): @loader_option() +def raiseload(loadopt, attr): + """Indicate that the given relationship attribute should remain unloaded. + + Accessing the relationship attribute anyway raises an + :exc:`~sqlalchemy.exc.InvalidRequestError`. + + This function is part of the :class:`.Load` interface and supports + both method-chained and standalone operation. + + :func:`.orm.raiseload` applies to :func:`.relationship` attributes only. + + .. versionadded:: 1.1.0 + """ + + return loadopt.set_relationship_strategy(attr, {"lazy": "raise"}) + + +@raiseload._add_unbound_fn +def raiseload(*keys): + return _UnboundLoad._from_keys(_UnboundLoad.raiseload, keys, False, {}) + + +@loader_option() def defaultload(loadopt, attr): """Indicate an attribute should load using its default loader style. |