Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

DDC-1618 - Query::Iterate() with fetch join exception but no associaiton selected #271

Merged
merged 2 commits into from

2 participants

@rande

No description provided.

@beberlei beberlei merged commit 94162d1 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 24, 2012
  1. @rande
  2. @rande
This page is out of date. Refresh to see the latest.
View
12 lib/Doctrine/ORM/Query/SqlWalker.php
@@ -36,6 +36,11 @@
class SqlWalker implements TreeWalker
{
/**
+ * @var string
+ */
+ const HINT_DISTINCT = 'doctrine.distinct';
+
+ /**
* @var ResultSetMapping
*/
private $_rsm;
@@ -516,6 +521,10 @@ public function walkSelectClause($selectClause)
$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
||
@@ -736,8 +745,7 @@ public function walkJoinVariableDeclaration($joinVarDecl)
// 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) {
+ 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);
}
View
24 tests/Doctrine/Tests/ORM/Query/QueryTest.php
@@ -90,4 +90,28 @@ public function testHints()
$this->assertEquals('baz', $q->getHint('bar'));
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $q->getHints());
}
+
+ /**
+ * @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();
+ }
}
Something went wrong with that request. Please try again.