summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/strategy_options.py
diff options
context:
space:
mode:
authorAdrian Moennich <adrian@planetcoding.net>2015-08-11 23:08:28 +0200
committerAdrian Moennich <adrian@planetcoding.net>2015-08-12 18:39:43 +0200
commit6d334da16553c91cbe82de7134042dbe3c511630 (patch)
treedb66cc1463a64ec7cb2d9f986521d3d567e659da /lib/sqlalchemy/orm/strategy_options.py
parent5198b1de31029cc985102cd13569086a7056c2f1 (diff)
downloadsqlalchemy-pr/193.tar.gz
Add raise/raiseload relationship loading strategypr/193
- available via `lazy='raise'` or by setting the `raiseload` strategy via `options()` - behaves almost like `lazy='noload'`, but instead of returning `None` it raises `InvalidRequestError` - based on code from Mike Bayer that was posted to the sqlalchemy mailing list: https://groups.google.com/forum/#!topic/sqlalchemy/X_wA8K97smE
Diffstat (limited to 'lib/sqlalchemy/orm/strategy_options.py')
-rw-r--r--lib/sqlalchemy/orm/strategy_options.py23
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.