Skip to content

Commit

Permalink
Merge pull request #6812 from Deltachaos/bugfix/inheritance-joins-master
Browse files Browse the repository at this point in the history
Fix syntax error when join unrelated entity with discriminator entity
  • Loading branch information
lcobucci committed Dec 17, 2017
2 parents 0837493 + 32c125d commit d3ff823
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Expand Up @@ -902,15 +902,17 @@ private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration,
$this->query->getHint(Query::HINT_LOCK_MODE)
);

if ($class->isInheritanceTypeJoined()) {
if ($buildNestedJoins) {
$sql = '(' . $sql . $this->_generateClassTableInheritanceJoins($class, $dqlAlias) . ')';
} else {
$sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias);
}
if ( ! $class->isInheritanceTypeJoined()) {
return $sql;
}

return $sql;
$classTableInheritanceJoins = $this->_generateClassTableInheritanceJoins($class, $dqlAlias);

if ( ! $buildNestedJoins) {
return $sql . $classTableInheritanceJoins;
}

return $classTableInheritanceJoins === '' ? $sql : '(' . $sql . $classTableInheritanceJoins . ')';
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
Expand Up @@ -205,6 +205,11 @@ public function testSupportsJoinOnMultipleComponentsWithJoinedInheritanceType()
'SELECT e FROM Doctrine\Tests\Models\Company\CompanyEmployee e LEFT JOIN Doctrine\Tests\Models\Company\CompanyManager m WITH e.id = m.id',
'SELECT c0_.id AS id_0, c0_.name AS name_1, c1_.salary AS salary_2, c1_.department AS department_3, c1_.startDate AS startDate_4, c0_.discr AS discr_5 FROM company_employees c1_ INNER JOIN company_persons c0_ ON c1_.id = c0_.id LEFT JOIN (company_managers c2_ INNER JOIN company_employees c4_ ON c2_.id = c4_.id INNER JOIN company_persons c3_ ON c2_.id = c3_.id) ON (c0_.id = c3_.id)'
);

$this->assertSqlGeneration(
'SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c JOIN c.salesPerson s LEFT JOIN Doctrine\Tests\Models\Company\CompanyEvent e WITH s.id = e.id',
'SELECT c0_.id AS id_0, c0_.completed AS completed_1, c0_.fixPrice AS fixPrice_2, c0_.hoursWorked AS hoursWorked_3, c0_.pricePerHour AS pricePerHour_4, c0_.maxPrice AS maxPrice_5, c0_.discr AS discr_6 FROM company_contracts c0_ INNER JOIN company_employees c1_ ON c0_.salesPerson_id = c1_.id LEFT JOIN company_persons c2_ ON c1_.id = c2_.id LEFT JOIN company_events c3_ ON (c2_.id = c3_.id) WHERE c0_.discr IN (\'fix\', \'flexible\', \'flexultra\')'
);
}

public function testSupportsSelectWithCollectionAssociationJoin()
Expand Down

0 comments on commit d3ff823

Please sign in to comment.