diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-10-23 00:40:29 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-10-23 00:43:11 -0400 |
| commit | 47d316ec665e5d5fc7ac750ba62b189a64d98ddd (patch) | |
| tree | 0754543be3559ba7f262306b314a6d873e745867 | |
| parent | 56d5732fbdf09508784df6dc4c04e5b39ac6be85 (diff) | |
| download | sqlalchemy-47d316ec665e5d5fc7ac750ba62b189a64d98ddd.tar.gz | |
- 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
| -rw-r--r-- | doc/build/changelog/changelog_09.rst | 13 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 7 | ||||
| -rw-r--r-- | test/orm/inheritance/test_single.py | 25 |
3 files changed, 43 insertions, 2 deletions
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 8687284e8..fe8dc0150 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -11,6 +11,19 @@ :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 fce7a3665..dc09e8eb4 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 6112929b6..967c07150 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, |
