Fix DDC-1618 - add more check before throwing an iterateWithFetchJoinNotAllowed exception
This commit is contained in:
parent
8bf1c96ae1
commit
d9bb861b1f
@ -590,6 +590,10 @@ class SqlWalker implements TreeWalker
|
|||||||
$sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : '');
|
$sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : '');
|
||||||
$sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions));
|
$sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions));
|
||||||
|
|
||||||
|
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) {
|
||||||
|
$this->_query->setHint('doctrine.distinct', true);
|
||||||
|
}
|
||||||
|
|
||||||
$addMetaColumns = ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) &&
|
$addMetaColumns = ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) &&
|
||||||
$this->_query->getHydrationMode() == Query::HYDRATE_OBJECT
|
$this->_query->getHydrationMode() == Query::HYDRATE_OBJECT
|
||||||
||
|
||
|
||||||
@ -811,10 +815,11 @@ class SqlWalker implements TreeWalker
|
|||||||
|
|
||||||
// Ensure we got the owning side, since it has all mapping info
|
// Ensure we got the owning side, since it has all mapping info
|
||||||
$assoc = ( ! $relation['isOwningSide']) ? $targetClass->associationMappings[$relation['mappedBy']] : $relation;
|
$assoc = ( ! $relation['isOwningSide']) ? $targetClass->associationMappings[$relation['mappedBy']] : $relation;
|
||||||
|
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && (!$this->_query->getHint('doctrine.distinct') || isset($this->_selectedClasses[$joinedDqlAlias]))) {
|
||||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $relation['type'] & ClassMetadata::TO_MANY) {
|
if ($relation['type'] == ClassMetadata::ONE_TO_MANY || $relation['type'] == ClassMetadata::MANY_TO_MANY) {
|
||||||
throw QueryException::iterateWithFetchJoinNotAllowed($assoc);
|
throw QueryException::iterateWithFetchJoinNotAllowed($assoc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($joinVarDecl->indexBy) {
|
if ($joinVarDecl->indexBy) {
|
||||||
// For Many-To-One or One-To-One associations this obviously makes no sense, but is ignored silently.
|
// For Many-To-One or One-To-One associations this obviously makes no sense, but is ignored silently.
|
||||||
|
@ -101,4 +101,28 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$q->useResultCache(true);
|
$q->useResultCache(true);
|
||||||
$this->assertSame($this->_em->getConfiguration()->getResultCacheImpl(), $q->getQueryCacheProfile()->getResultCacheDriver());
|
$this->assertSame($this->_em->getConfiguration()->getResultCacheImpl(), $q->getQueryCacheProfile()->getResultCacheDriver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Doctrine\ORM\Query\QueryException
|
||||||
|
**/
|
||||||
|
public function testIterateWithNoDistinctAndWrongSelectClause()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a");
|
||||||
|
$q->iterate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Doctrine\ORM\Query\QueryException
|
||||||
|
**/
|
||||||
|
public function testIterateWithNoDistinctAndWithValidSelectClause()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a");
|
||||||
|
$q->iterate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIterateWithDistinct()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery("SELECT DISTINCT u from Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a");
|
||||||
|
$q->iterate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user