Added support for NEW operator when using ArrayHydration if user desires to benefit from this funcionality.
This commit is contained in:
parent
63d21ca4b2
commit
29de3e00ff
@ -121,6 +121,17 @@ class ArrayHydrator extends AbstractHydrator
|
||||
}
|
||||
}
|
||||
|
||||
// Extract "new" object constructor arguments. They're appended at the end.
|
||||
if (isset($rowData['newObjects'])) {
|
||||
$newObjects = $rowData['newObjects'];
|
||||
|
||||
unset($rowData['newObjects']);
|
||||
|
||||
if (empty($rowData)) {
|
||||
++$this->_resultCounter;
|
||||
}
|
||||
}
|
||||
|
||||
// 2) Now hydrate the data found in the current row.
|
||||
foreach ($rowData as $dqlAlias => $data) {
|
||||
$index = false;
|
||||
@ -262,6 +273,29 @@ class ArrayHydrator extends AbstractHydrator
|
||||
$result[$resultKey][$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Append new object to mixed result sets
|
||||
if (isset($newObjects)) {
|
||||
if ( ! isset($resultKey) ) {
|
||||
$resultKey = $this->_resultCounter - 1;
|
||||
}
|
||||
|
||||
$count = count($newObjects);
|
||||
|
||||
foreach ($newObjects as $objIndex => $newObject) {
|
||||
$class = $newObject['class'];
|
||||
$args = $newObject['args'];
|
||||
$obj = $class->newInstanceArgs($args);
|
||||
|
||||
if ($count === 1) {
|
||||
$result[$resultKey] = $obj;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$resultKey][$objIndex] = $obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\CMS\CmsEmail;
|
||||
use Doctrine\Tests\Models\CMS\CmsAddress;
|
||||
@ -12,7 +13,6 @@ use Doctrine\Tests\Models\CMS\CmsPhonenumber;
|
||||
*/
|
||||
class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@ -26,6 +26,14 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->loadFixtures();
|
||||
}
|
||||
|
||||
public function provideDataForHydrationMode()
|
||||
{
|
||||
return array(
|
||||
array(Query::HYDRATE_ARRAY),
|
||||
array(Query::HYDRATE_OBJECT),
|
||||
);
|
||||
}
|
||||
|
||||
private function loadFixtures()
|
||||
{
|
||||
$u1 = new CmsUser;
|
||||
@ -87,7 +95,10 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->fixtures = array($u1, $u2, $u3);
|
||||
}
|
||||
|
||||
public function testShouldSupportsBasicUsage()
|
||||
/**
|
||||
* @dataProvider provideDataForHydrationMode
|
||||
*/
|
||||
public function testShouldSupportsBasicUsage($hydrationMode)
|
||||
{
|
||||
$dql = "
|
||||
SELECT
|
||||
@ -106,7 +117,7 @@ class NewOperatorTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
u.name";
|
||||
|
||||
$query = $this->_em->createQuery($dql);
|
||||
$result = $query->getResult();
|
||||
$result = $query->getResult($hydrationMode);
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user