From 7f1c1d2b4acca7596d82ece885fd491537cdf230 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Tue, 13 Aug 2013 01:07:34 -0400 Subject: [PATCH] Fixed DDC-2506 by manually updating code. Closes PR #708. --- lib/Doctrine/ORM/Query/SqlWalker.php | 21 ++++++++++--------- .../ORM/Query/SelectSqlGenerationTest.php | 12 +++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index fe923c953..cf66f66a7 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -858,13 +858,14 @@ class SqlWalker implements TreeWalker * Walks down a JoinAssociationDeclaration AST node, thereby generating the appropriate SQL. * * @param AST\JoinAssociationDeclaration $joinAssociationDeclaration - * @param int $joinType + * @param int $joinType + * @param AST\ConditionalExpression $condExpr * * @return string * * @throws QueryException */ - public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joinType = AST\Join::JOIN_TYPE_INNER) + public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joinType = AST\Join::JOIN_TYPE_INNER, $condExpr = null) { $sql = ''; @@ -979,6 +980,13 @@ class SqlWalker implements TreeWalker break; } + // Handle WITH clause + if ($condExpr !== null) { + // Phase 2 AST optimization: Skip processing of ConditionalExpression + // if only one ConditionalTerm is defined + $sql .= ' AND (' . $this->walkConditionalExpression($condExpr) . ')'; + } + // FIXME: these should either be nested or all forced to be left joins (DDC-XXX) if ($targetClass->isInheritanceTypeJoined()) { $sql .= $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias); @@ -1068,14 +1076,7 @@ class SqlWalker implements TreeWalker break; case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\JoinAssociationDeclaration): - $sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType); - - // Handle WITH clause - if (($condExpr = $join->conditionalExpression) !== null) { - // Phase 2 AST optimization: Skip processing of ConditionalExpression - // if only one ConditionalTerm is defined - $sql .= ' AND (' . $this->walkConditionalExpression($condExpr) . ')'; - } + $sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType, $join->conditionalExpression); break; } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index a444a2e87..0ec3afe17 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -2040,6 +2040,18 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + /** + * @group DDC-2506 + */ + public function testClassTableInheritanceJoinWithConditionAppliesToBaseTable() + { + $this->assertSqlGeneration( + 'SELECT e.id FROM Doctrine\Tests\Models\Company\CompanyOrganization o JOIN o.events e WITH e.id = ?1', + 'SELECT c0_.id AS id0 FROM company_organizations c1_ INNER JOIN company_events c0_ ON c1_.id = c0_.org_id AND (c0_.id = ?) LEFT JOIN company_auctions c2_ ON c0_.id = c2_.id LEFT JOIN company_raffles c3_ ON c0_.id = c3_.id', + array(Query::HINT_FORCE_PARTIAL_LOAD => false) + ); + } + /** * @group DDC-1858 */