summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r--lib/sqlalchemy/ext/baked.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/baked.py b/lib/sqlalchemy/ext/baked.py
index f01e0b348..a933e7eb7 100644
--- a/lib/sqlalchemy/ext/baked.py
+++ b/lib/sqlalchemy/ext/baked.py
@@ -283,6 +283,26 @@ class Result(object):
raise orm_exc.MultipleResultsFound(
"Multiple rows were found for one()")
+ def one_or_none(self):
+ """Return one or zero results, or raise an exception for multiple
+ rows.
+
+ Equivalent to :meth:`.Query.one_or_none`.
+
+ .. versionadded:: 1.0.9
+
+ """
+ ret = list(self)
+
+ l = len(ret)
+ if l == 1:
+ return ret[0]
+ elif l == 0:
+ return None
+ else:
+ raise orm_exc.MultipleResultsFound(
+ "Multiple rows were found for one()")
+
def all(self):
"""Return all rows.