[DDC-1757] Fix moved to private method, test improved.
This commit is contained in:
parent
49016bc156
commit
aa381951cd
@ -97,8 +97,7 @@ class QueryBuilder
|
|||||||
private $_maxResults = null;
|
private $_maxResults = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps root entity alias names for join entities
|
* @var array Keeps root entity alias names for join entities.
|
||||||
* @var array
|
|
||||||
*/
|
*/
|
||||||
private $joinRootAliases = array();
|
private $joinRootAliases = array();
|
||||||
|
|
||||||
@ -225,6 +224,32 @@ class QueryBuilder
|
|||||||
->setMaxResults($this->_maxResults);
|
->setMaxResults($this->_maxResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the root entity alias of the joined entity.
|
||||||
|
*
|
||||||
|
* @param string $alias The alias of the new join entity
|
||||||
|
* @param string $parentAlias The parent entity alias of the join relationship
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function findRootAlias($alias, $parentAlias)
|
||||||
|
{
|
||||||
|
$rootAlias = null;
|
||||||
|
|
||||||
|
if (in_array($parentAlias, $this->getRootAliases())) {
|
||||||
|
$rootAlias = $parentAlias;
|
||||||
|
} elseif (isset($this->joinRootAliases[$parentAlias])) {
|
||||||
|
$rootAlias = $this->joinRootAliases[$parentAlias];
|
||||||
|
} else {
|
||||||
|
// Should never happen with correct joining order. Might be
|
||||||
|
// thoughtful to throw exception instead.
|
||||||
|
$rootAlias = $this->getRootAlias();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->joinRootAliases[$alias] = $rootAlias;
|
||||||
|
|
||||||
|
return $rootAlias;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the FIRST root alias of the query. This is the first entity alias involved
|
* Gets the FIRST root alias of the query. This is the first entity alias involved
|
||||||
* in the construction of the query.
|
* in the construction of the query.
|
||||||
@ -238,26 +263,12 @@ class QueryBuilder
|
|||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @deprecated Please use $qb->getRootAliases() instead.
|
* @deprecated Please use $qb->getRootAliases() instead.
|
||||||
* @param string $rootAlias
|
|
||||||
* @param string $alias
|
|
||||||
* @return string $rootAlias
|
* @return string $rootAlias
|
||||||
*/
|
*/
|
||||||
public function getRootAlias($rootAlias = null, $alias = null)
|
public function getRootAlias()
|
||||||
{
|
{
|
||||||
if ( ! is_null($rootAlias) && in_array($rootAlias, $this->getRootAliases())) {
|
$aliases = $this->getRootAliases();
|
||||||
// Do nothing
|
return $aliases[0];
|
||||||
} elseif ( ! is_null($rootAlias) && isset($this->joinRootAliases[$rootAlias])) {
|
|
||||||
$rootAlias = $this->joinRootAliases[$rootAlias];
|
|
||||||
} else {
|
|
||||||
$aliases = $this->getRootAliases();
|
|
||||||
$rootAlias = $aliases[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! is_null($alias)) {
|
|
||||||
$this->joinRootAliases[$alias] = $rootAlias;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rootAlias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -687,9 +698,9 @@ class QueryBuilder
|
|||||||
*/
|
*/
|
||||||
public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null)
|
public function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null)
|
||||||
{
|
{
|
||||||
$rootAlias = substr($join, 0, strpos($join, '.'));
|
$parentAlias = substr($join, 0, strpos($join, '.'));
|
||||||
|
|
||||||
$rootAlias = $this->getRootAlias($rootAlias, $alias);
|
$rootAlias = $this->findRootAlias($alias, $parentAlias);
|
||||||
|
|
||||||
$join = new Expr\Join(
|
$join = new Expr\Join(
|
||||||
Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy
|
Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition, $indexBy
|
||||||
@ -721,9 +732,9 @@ class QueryBuilder
|
|||||||
*/
|
*/
|
||||||
public function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null)
|
public function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null)
|
||||||
{
|
{
|
||||||
$rootAlias = substr($join, 0, strpos($join, '.'));
|
$parentAlias = substr($join, 0, strpos($join, '.'));
|
||||||
|
|
||||||
$rootAlias = $this->getRootAlias($rootAlias, $alias);
|
$rootAlias = $this->findRootAlias($alias, $parentAlias);
|
||||||
|
|
||||||
$join = new Expr\Join(
|
$join = new Expr\Join(
|
||||||
Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy
|
Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition, $indexBy
|
||||||
|
@ -33,9 +33,21 @@ class DDC1757Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
->join('_b.c', '_c')
|
->join('_b.c', '_c')
|
||||||
->join('_c.d', '_d');
|
->join('_c.d', '_d');
|
||||||
|
|
||||||
$q = $qb->getQuery();
|
$q = $qb->getQuery();
|
||||||
$dql = $q->getDQL();
|
$dql = $q->getDQL();
|
||||||
$q->getResult();
|
|
||||||
|
try {
|
||||||
|
$data = $q->getResult();
|
||||||
|
|
||||||
|
self::assertEmpty($data);
|
||||||
|
} catch (\Doctrine\ORM\Query\QueryException $queryException) {
|
||||||
|
// Show difference between expected and actual queries on error
|
||||||
|
self::assertEquals("SELECT _a FROM " . __NAMESPACE__ . "\DDC1757A _a, " . __NAMESPACE__ . "\DDC1757B _b INNER JOIN _b.c _c INNER JOIN _c.d _d",
|
||||||
|
$dql,
|
||||||
|
"Wrong DQL query: " . $queryException->getMessage());
|
||||||
|
|
||||||
|
throw new \RuntimeException("Unexpected issue. DQL is correct but the query is failing.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user