Merge branch 'DDC-1618'
This commit is contained in:
commit
f0a09a2d52
@ -39,6 +39,11 @@ use Doctrine\DBAL\LockMode,
|
||||
*/
|
||||
class SqlWalker implements TreeWalker
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const HINT_DISTINCT = 'doctrine.distinct';
|
||||
|
||||
/**
|
||||
* @var ResultSetMapping
|
||||
*/
|
||||
@ -590,6 +595,10 @@ class SqlWalker implements TreeWalker
|
||||
$sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : '');
|
||||
$sqlSelectExpressions = array_filter(array_map(array($this, 'walkSelectExpression'), $selectClause->selectExpressions));
|
||||
|
||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) {
|
||||
$this->_query->setHint(self::HINT_DISTINCT, true);
|
||||
}
|
||||
|
||||
$addMetaColumns = ! $this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) &&
|
||||
$this->_query->getHydrationMode() == Query::HYDRATE_OBJECT
|
||||
||
|
||||
@ -811,10 +820,11 @@ class SqlWalker implements TreeWalker
|
||||
|
||||
// Ensure we got the owning side, since it has all mapping info
|
||||
$assoc = ( ! $relation['isOwningSide']) ? $targetClass->associationMappings[$relation['mappedBy']] : $relation;
|
||||
|
||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $relation['type'] & ClassMetadata::TO_MANY) {
|
||||
if ($this->_query->getHint(Query::HINT_INTERNAL_ITERATION) == true && (!$this->_query->getHint(self::HINT_DISTINCT) || isset($this->_selectedClasses[$joinedDqlAlias]))) {
|
||||
if ($relation['type'] == ClassMetadata::ONE_TO_MANY || $relation['type'] == ClassMetadata::MANY_TO_MANY) {
|
||||
throw QueryException::iterateWithFetchJoinNotAllowed($assoc);
|
||||
}
|
||||
}
|
||||
|
||||
if ($joinVarDecl->indexBy) {
|
||||
// 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);
|
||||
$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