summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/interfaces.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-02-21 01:01:24 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-02-21 01:01:24 +0000
commit334668d904ae31eea6bf8d7035f9088c69df78ee (patch)
tree4a8078f46c58ed24a2dfa2270fcc9fbcaf197fc1 /lib/sqlalchemy/orm/interfaces.py
parentf827e3c0b7d7493ec94f8f3c0ee69c78c3441bb8 (diff)
downloadsqlalchemy-334668d904ae31eea6bf8d7035f9088c69df78ee.tar.gz
- added a new "higher level" operator called "of_type()" -
used in join() as well as with any() and has(), qualifies the subclass which will be used in filter criterion, e.g.: query.filter(Company.employees.of_type(Engineer). any(Engineer.name=='foo')), query.join(Company.employees.of_type(Engineer)). filter(Engineer.name=='foo')
Diffstat (limited to 'lib/sqlalchemy/orm/interfaces.py')
-rw-r--r--lib/sqlalchemy/orm/interfaces.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index 2c3a98c88..f510a3ffa 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -435,8 +435,29 @@ class PropComparator(expression.ColumnOperators):
has_op = staticmethod(has_op)
def __init__(self, prop):
- self.prop = prop
-
+ self.prop = self.property = prop
+
+ def of_type_op(a, class_):
+ return a.of_type(class_)
+ of_type_op = staticmethod(of_type_op)
+
+ def of_type(self, class_):
+ """Redefine this object in terms of a polymorphic subclass.
+
+ Returns a new PropComparator from which further criterion can be evaulated.
+
+ class_
+ a class or mapper indicating that criterion will be against
+ this specific subclass.
+
+ e.g.::
+ query.join(Company.employees.of_type(Engineer)).\
+ filter(Engineer.name=='foo')
+
+ """
+
+ return self.operate(PropComparator.of_type_op, class_)
+
def contains(self, other):
"""Return true if this collection contains other"""
return self.operate(PropComparator.contains_op, other)