1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Fixed DDC-2506 by manually updating code. Closes PR #708.

This commit is contained in:
Guilherme Blanco 2013-08-13 01:07:34 -04:00 committed by Benjamin Eberlei
parent dbb7c4d2bf
commit 62b4160887
2 changed files with 23 additions and 10 deletions

View File

@ -859,12 +859,13 @@ class SqlWalker implements TreeWalker
* *
* @param AST\JoinAssociationDeclaration $joinAssociationDeclaration * @param AST\JoinAssociationDeclaration $joinAssociationDeclaration
* @param int $joinType * @param int $joinType
* @param AST\ConditionalExpression $condExpr
* *
* @return string * @return string
* *
* @throws QueryException * @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 = ''; $sql = '';
@ -979,6 +980,13 @@ class SqlWalker implements TreeWalker
break; 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) // FIXME: these should either be nested or all forced to be left joins (DDC-XXX)
if ($targetClass->isInheritanceTypeJoined()) { if ($targetClass->isInheritanceTypeJoined()) {
$sql .= $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias); $sql .= $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias);
@ -1068,14 +1076,7 @@ class SqlWalker implements TreeWalker
break; break;
case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\JoinAssociationDeclaration): case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\JoinAssociationDeclaration):
$sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType); $sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType, $join->conditionalExpression);
// 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) . ')';
}
break; break;
} }

View File

@ -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 * @group DDC-1858
*/ */