Skip to content

Commit

Permalink
#6464 code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Siegl authored and Ocramius committed Aug 11, 2017
1 parent 99fdbf5 commit 025ed11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
23 changes: 18 additions & 5 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,23 @@ public function walkIndexBy($indexBy)
* Walks down a RangeVariableDeclaration AST node, thereby generating the appropriate SQL.
*
* @param AST\RangeVariableDeclaration $rangeVariableDeclaration
*
* @return string
*/
public function walkRangeVariableDeclaration($rangeVariableDeclaration)
{
return $this->generateRangeVariableDeclarationSQL($rangeVariableDeclaration, false);
}

/**
* Generate appropriate SQL for RangeVariableDeclaration AST node
*
* @param AST\RangeVariableDeclaration $rangeVariableDeclaration
* @param bool $buildNestedJoins
*
* @return string
*/
public function walkRangeVariableDeclaration($rangeVariableDeclaration, $buildNestedJoins = false)
private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, $buildNestedJoins)
{
$class = $this->em->getClassMetadata($rangeVariableDeclaration->abstractSchemaName);
$dqlAlias = $rangeVariableDeclaration->aliasIdentificationVariable;
Expand Down Expand Up @@ -1132,7 +1144,7 @@ public function walkJoin($join)
: ' INNER JOIN ';

switch (true) {
case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\RangeVariableDeclaration):
case ($joinDeclaration instanceof AST\RangeVariableDeclaration):
$class = $this->em->getClassMetadata($joinDeclaration->abstractSchemaName);
$dqlAlias = $joinDeclaration->aliasIdentificationVariable;
$tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias);
Expand All @@ -1142,11 +1154,12 @@ public function walkJoin($join)
$conditions[] = '(' . $this->walkConditionalExpression($join->conditionalExpression) . ')';
}

$condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER && empty($conditions))
$isUnconditionalJoin = empty($conditions);
$condExprConjunction = ($class->isInheritanceTypeJoined() && $joinType != AST\Join::JOIN_TYPE_LEFT && $joinType != AST\Join::JOIN_TYPE_LEFTOUTER && $isUnconditionalJoin)
? ' AND '
: ' ON ';

$sql .= $this->walkRangeVariableDeclaration($joinDeclaration, !empty($conditions));
$sql .= $this->generateRangeVariableDeclarationSQL($joinDeclaration, !$isUnconditionalJoin);

// Apply remaining inheritance restrictions
$discrSql = $this->_generateDiscriminatorColumnConditionSQL([$dqlAlias]);
Expand All @@ -1168,7 +1181,7 @@ public function walkJoin($join)

break;

case ($joinDeclaration instanceof \Doctrine\ORM\Query\AST\JoinAssociationDeclaration):
case ($joinDeclaration instanceof AST\JoinAssociationDeclaration):
$sql .= $this->walkJoinAssociationDeclaration($joinDeclaration, $joinType, $join->conditionalExpression);
break;
}
Expand Down
13 changes: 1 addition & 12 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ protected function setUp()
*/
public function testIssue()
{

$qb = $this->_em->createQueryBuilder();

$query = $qb
$query = $this->_em->createQueryBuilder()
->select('p', 'a')
->from(GH6464Post::class, 'p')
->innerJoin(GH6464Author::class, 'a', 'WITH', 'p.authorId = a.id')
Expand All @@ -61,12 +58,6 @@ class GH6464Post

/** @Column(type="integer") */
public $authorId;

/** @Column(length=100) */
public $title;

/** @Column(type="text") */
public $text;
}

/**
Expand All @@ -84,6 +75,4 @@ abstract class GH6464User
/** @Entity */
class GH6464Author extends GH6464User
{
/** @Column(length=50) */
public $displayName;
}

0 comments on commit 025ed11

Please sign in to comment.