From: Mike Bayer Date: Fri, 15 Jan 2010 19:04:50 +0000 (+0000) Subject: restore common_parent logic in correspoinds_to, fixes [ticket:1657] X-Git-Tag: rel_0_6beta1~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f72378137a855098c4f0c1c830e3b244634cbd84;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git restore common_parent logic in correspoinds_to, fixes [ticket:1657] --- diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index fc83f91959..7be0680197 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -2038,10 +2038,10 @@ class _MapperEntity(_QueryEntity): self.adapter = query._get_polymorphic_adapter(self, from_obj) def corresponds_to(self, entity): - if _is_aliased_class(entity): + if _is_aliased_class(entity) or self.is_aliased_class: return entity is self.path_entity else: - return entity.isa(self.path_entity) + return entity.common_parent(self.path_entity) def adapt_to_selectable(self, query, sel): query._entities.append(self) diff --git a/test/orm/inheritance/test_query.py b/test/orm/inheritance/test_query.py index 1a7d09e92e..256eaefa6a 100644 --- a/test/orm/inheritance/test_query.py +++ b/test/orm/inheritance/test_query.py @@ -503,6 +503,12 @@ def _produce_test(select_type): ) self.assert_sql_count(testing.db, go, 1) + + def test_query_subclass_join_to_base_relation(self): + sess = create_session() + # non-polymorphic + eq_(sess.query(Engineer).join(Person.paperwork).all(), [e1, e2, e3]) + def test_join_to_subclass(self): sess = create_session() eq_(sess.query(Company).join(('employees', people.join(engineers))).filter(Engineer.primary_language=='java').all(), [c1])