Merge branch 'DDC-1070'
This commit is contained in:
commit
efe26d00a1
@ -501,10 +501,20 @@ abstract class AbstractQuery
|
||||
* @param integer $hydrationMode The hydration mode to use.
|
||||
* @return IterableResult
|
||||
*/
|
||||
public function iterate(array $params = array(), $hydrationMode = self::HYDRATE_OBJECT)
|
||||
public function iterate(array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
if ($hydrationMode !== null) {
|
||||
$this->setHydrationMode($hydrationMode);
|
||||
}
|
||||
|
||||
if ($params) {
|
||||
$this->setParameters($params);
|
||||
}
|
||||
|
||||
$stmt = $this->_doExecute();
|
||||
|
||||
return $this->_em->newHydrator($this->_hydrationMode)->iterate(
|
||||
$this->_doExecute($params, $hydrationMode), $this->_resultSetMapping, $this->_hints
|
||||
$stmt, $this->_resultSetMapping, $this->_hints
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser,
|
||||
Doctrine\Tests\Models\CMS\CmsArticle;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
@ -136,6 +137,38 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$users = $q->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1070
|
||||
*/
|
||||
public function testIterateResultAsArrayAndParams()
|
||||
{
|
||||
$article1 = new CmsArticle;
|
||||
$article1->topic = "Doctrine 2";
|
||||
$article1->text = "This is an introduction to Doctrine 2.";
|
||||
|
||||
$article2 = new CmsArticle;
|
||||
$article2->topic = "Symfony 2";
|
||||
$article2->text = "This is an introduction to Symfony 2.";
|
||||
|
||||
$this->_em->persist($article1);
|
||||
$this->_em->persist($article2);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$query = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1");
|
||||
$articles = $query->iterate(array(1 => 'Doctrine 2'), Query::HYDRATE_ARRAY);
|
||||
|
||||
$found = array();
|
||||
foreach ($articles AS $article) {
|
||||
$found[] = $article;
|
||||
}
|
||||
$this->assertEquals(1, count($found));
|
||||
$this->assertEquals(array(
|
||||
array(array('id' => 1, 'topic' => 'Doctrine 2', 'text' => 'This is an introduction to Doctrine 2.', 'version' => 1))
|
||||
), $found);
|
||||
}
|
||||
|
||||
public function testIterateResult_IterativelyBuildUpUnitOfWork()
|
||||
{
|
||||
$article1 = new CmsArticle;
|
||||
|
Loading…
Reference in New Issue
Block a user