summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/operators.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-01-31 19:14:08 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-01-31 19:14:08 -0500
commit6b3ecd14eae1a557cffd19da6c82d967586a6d74 (patch)
tree362fa6f32cb2f7a0f4d32722259ef573b222cdd2 /lib/sqlalchemy/sql/operators.py
parentb360dbf7ebb7cc5bb290847fdd9818d205244a94 (diff)
downloadsqlalchemy-6b3ecd14eae1a557cffd19da6c82d967586a6d74.tar.gz
- Added a new parameter :paramref:`.Operators.op.is_comparison`. This
flag allows a custom op from :meth:`.Operators.op` to be considered as a "comparison" operator, thus usable for custom :paramref:`.relationship.primaryjoin` conditions.
Diffstat (limited to 'lib/sqlalchemy/sql/operators.py')
-rw-r--r--lib/sqlalchemy/sql/operators.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index d7ec977aa..91301c78c 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -102,7 +102,7 @@ class Operators(object):
"""
return self.operate(inv)
- def op(self, opstring, precedence=0):
+ def op(self, opstring, precedence=0, is_comparison=False):
"""produce a generic operator function.
e.g.::
@@ -134,12 +134,23 @@ class Operators(object):
.. versionadded:: 0.8 - added the 'precedence' argument.
+ :param is_comparison: if True, the operator will be considered as a
+ "comparison" operator, that is which evaulates to a boolean true/false
+ value, like ``==``, ``>``, etc. This flag should be set so that
+ ORM relationships can establish that the operator is a comparison
+ operator when used in a custom join condition.
+
+ .. versionadded:: 0.9.2 - added the :paramref:`.Operators.op.is_comparison`
+ flag.
+
.. seealso::
:ref:`types_operators`
+ :ref:`relationship_custom_operator`
+
"""
- operator = custom_op(opstring, precedence)
+ operator = custom_op(opstring, precedence, is_comparison)
def against(other):
return operator(self, other)
@@ -200,9 +211,10 @@ class custom_op(object):
"""
__name__ = 'custom_op'
- def __init__(self, opstring, precedence=0):
+ def __init__(self, opstring, precedence=0, is_comparison=False):
self.opstring = opstring
self.precedence = precedence
+ self.is_comparison = is_comparison
def __eq__(self, other):
return isinstance(other, custom_op) and \
@@ -769,7 +781,8 @@ _comparison = set([eq, ne, lt, gt, ge, le, between_op])
def is_comparison(op):
- return op in _comparison
+ return op in _comparison or \
+ isinstance(op, custom_op) and op.is_comparison
def is_commutative(op):