``lt``, ``gt``, etc.) using :meth:`.Operators.operate`::
class CaseInsensitiveComparator(Comparator):
- def operate(self, op, other):
- return op(func.lower(self.__clause_element__()), func.lower(other))
+ def operate(self, op, other, **kwargs):
+ return op(
+ func.lower(self.__clause_element__()),
+ func.lower(other),
+ **kwargs,
+ )
.. _hybrid_reuse_subclass:
else:
self.word = func.lower(word)
- def operate(self, op, other):
+ def operate(self, op, other, **kwargs):
if not isinstance(other, CaseInsensitiveWord):
other = CaseInsensitiveWord(other)
- return op(self.word, other.word)
+ return op(self.word, other.word, **kwargs)
def __clause_element__(self):
return self.word
from sqlalchemy.ext.hybrid import Comparator
class GrandparentTransformer(Comparator):
- def operate(self, op, other):
+ def operate(self, op, other, **kwargs):
def transform(q):
cls = self.__clause_element__()
parent_alias = aliased(cls)
- return q.join(parent_alias, cls.parent).\
- filter(op(parent_alias.parent, other))
+ return q.join(parent_alias, cls.parent).filter(
+ op(parent_alias.parent, other, **kwargs)
+ )
+
return transform
Base = declarative_base()
return q.join(self.parent_alias, Node.parent)
return go
- def operate(self, op, other):
- return op(self.parent_alias.parent, other)
+ def operate(self, op, other, **kwargs):
+ return op(self.parent_alias.parent, other, **kwargs)
.. sourcecode:: pycon+sql
side::
class MyComparator(ColumnOperators):
- def operate(self, op, other):
- return op(func.lower(self), func.lower(other))
+ def operate(self, op, other, **kwargs):
+ return op(func.lower(self), func.lower(other), **kwargs)
:param op: Operator callable.
:param \*other: the 'other' side of the operation. Will