]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where the ON clause for :meth:`.Query.join`,
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 23 Oct 2014 04:40:29 +0000 (00:40 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 23 Oct 2014 04:43:11 +0000 (00:43 -0400)
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

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/orm/query.py
test/orm/inheritance/test_single.py

index 8687284e8046293055f492c53fa585f53ff433be..fe8dc015057e6f84b2d35b2e28aed63f0b4b9a21 100644 (file)
     .. 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
index fce7a3665c316d931d78db2d07a8b049fde6e6b8..dc09e8eb43b4637b85c3d06c8a03cf2206d5e079 100644 (file)
@@ -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:
index 6112929b631877f591238da355908a85af762ef0..967c07150dc915f674386401c84468b3d546dec3 100644 (file)
@@ -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,