From: Mike Bayer Date: Thu, 23 Oct 2014 04:40:29 +0000 (-0400) Subject: - Fixed bug where the ON clause for :meth:`.Query.join`, X-Git-Tag: rel_1_0_0b1~70^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47d316ec665e5d5fc7ac750ba62b189a64d98ddd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug where the ON clause for :meth:`.Query.join`, and :meth:`.Query.outerjoin` to a single-inheritance subclass using ``of_type()`` would not render the "single table criteria" in the ON clause if the ``from_joinpoint=True`` flag were set. fixes #3232 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 8687284e80..fe8dc01505 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -10,6 +10,19 @@ .. include:: changelog_07.rst :start-line: 5 +.. changelog:: + :version: 0.9.9 + + .. change:: + :tags: bug, orm + :tickets: 3232 + :versions: 1.0.0 + + Fixed bug where the ON clause for :meth:`.Query.join`, + and :meth:`.Query.outerjoin` to a single-inheritance subclass + using ``of_type()`` would not render the "single table criteria" in + the ON clause if the ``from_joinpoint=True`` flag were set. + .. changelog:: :version: 0.9.8 :released: October 13, 2014 diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index fce7a3665c..dc09e8eb43 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1835,6 +1835,11 @@ class Query(object): left_entity = prop = None + if isinstance(onclause, interfaces.PropComparator): + of_type = getattr(onclause, '_of_type', None) + else: + of_type = None + if isinstance(onclause, util.string_types): left_entity = self._joinpoint_zero() @@ -1861,8 +1866,6 @@ class Query(object): if isinstance(onclause, interfaces.PropComparator): if right_entity is None: - right_entity = onclause.property.mapper - of_type = getattr(onclause, '_of_type', None) if of_type: right_entity = of_type else: diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py index 6112929b63..967c07150d 100644 --- a/test/orm/inheritance/test_single.py +++ b/test/orm/inheritance/test_single.py @@ -386,6 +386,30 @@ class RelationshipToSingleTest(testing.AssertsCompiledSQL, fixtures.MappedTest): ] ) + def test_of_type_aliased_fromjoinpoint(self): + Company, Employee, Engineer = self.classes.Company,\ + self.classes.Employee,\ + self.classes.Engineer + companies, employees = self.tables.companies, self.tables.employees + + mapper(Company, companies, properties={ + 'employee':relationship(Employee) + }) + mapper(Employee, employees, polymorphic_on=employees.c.type) + mapper(Engineer, inherits=Employee, polymorphic_identity='engineer') + + sess = create_session() + self.assert_compile( + sess.query(Company).outerjoin( + Company.employee.of_type(Engineer), + aliased=True, from_joinpoint=True), + "SELECT companies.company_id AS companies_company_id, " + "companies.name AS companies_name FROM companies " + "LEFT OUTER JOIN employees AS employees_1 ON " + "companies.company_id = employees_1.company_id " + "AND employees_1.type IN (:type_1)" + ) + def test_outer_join_prop(self): Company, Employee, Engineer = self.classes.Company,\ self.classes.Employee,\ @@ -549,6 +573,7 @@ class RelationshipToSingleTest(testing.AssertsCompiledSQL, fixtures.MappedTest): "AND employees_1.type IN (:type_1)" ) + def test_relationship_to_subclass(self): JuniorEngineer, Company, companies, Manager, \ Employee, employees, Engineer = (self.classes.JuniorEngineer,