From 8d295ec1189576f4ab918f8288812277567db6a1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 26 Feb 2009 15:16:06 +0000 Subject: [PATCH] - Fixed adaptation of EXISTS clauses via any(), has(), etc. in conjunction with an aliased object on the left and of_type() on the right. [ticket:1325] --- CHANGES | 4 ++++ lib/sqlalchemy/orm/properties.py | 4 ++-- test/orm/inheritance/query.py | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 5848a67965..f6fc99271b 100644 --- a/CHANGES +++ b/CHANGES @@ -51,6 +51,10 @@ CHANGES query(A).join(A.bs).filter(B.foo=='bar'), were erroneously adapting "B.foo" as though it were an "A". + - Fixed adaptation of EXISTS clauses via any(), has(), etc. + in conjunction with an aliased object on the left and + of_type() on the right. [ticket:1325] + - Added an attribute helper method ``set_committed_value`` in sqlalchemy.orm.attributes. Given an object, attribute name, and value, will set the value on the object as part of its diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 2a772dcac2..9c2268e014 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -472,7 +472,7 @@ class RelationProperty(StrategizedProperty): return op(self, *other, **kwargs) def of_type(self, cls): - return RelationProperty.Comparator(self.property, self.mapper, cls) + return RelationProperty.Comparator(self.property, self.mapper, cls, adapter=self.adapter) def in_(self, other): raise NotImplementedError("in_() not yet supported for relations. For a " @@ -511,7 +511,7 @@ class RelationProperty(StrategizedProperty): source_selectable = self.__clause_element__() else: source_selectable = None - + pj, sj, source, dest, secondary, target_adapter = \ self.property._create_joins(dest_polymorphic=True, dest_selectable=to_selectable, source_selectable=source_selectable) diff --git a/test/orm/inheritance/query.py b/test/orm/inheritance/query.py index ca789f8338..0f5d982f1d 100644 --- a/test/orm/inheritance/query.py +++ b/test/orm/inheritance/query.py @@ -280,6 +280,12 @@ def make_test(select_type): sess.query(Company).filter(Company.employees.of_type(Engineer).any(Engineer.primary_language=='cobol')).one(), c2 ) + + calias = aliased(Company) + self.assertEquals( + sess.query(calias).filter(calias.employees.of_type(Engineer).any(Engineer.primary_language=='cobol')).one(), + c2 + ) self.assertEquals( sess.query(Company).filter(Company.employees.of_type(Boss).any(Boss.golf_swing=='fore')).one(), -- 2.47.3