1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Hydration of fetch-joined results fails when an entity has a default value of array for the collection property

This commit is contained in:
Marco Pivetta 2015-04-02 23:43:16 +01:00
parent f495dfcc9c
commit 21b70577d3
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace Doctrine\Tests\Models\Hydration;
/** @Entity */
class EntityWithArrayDefaultArrayValueM2M
{
const CLASSNAME = __CLASS__;
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
public $id;
/** @ManyToMany(targetEntity=SimpleEntity::class) */
public $collection = [];
}

View File

@ -0,0 +1,12 @@
<?php
namespace Doctrine\Tests\Models\Hydration;
/** @Entity */
class SimpleEntity
{
const CLASSNAME = __CLASS__;
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
public $id;
}

View File

@ -8,6 +8,8 @@ use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query;
use Doctrine\Tests\Models\Hydration\EntityWithArrayDefaultArrayValueM2M;
use Doctrine\Tests\Models\Hydration\SimpleEntity;
use Doctrine\Tests\Models\CMS\CmsUser;
@ -1956,4 +1958,29 @@ class ObjectHydratorTest extends HydrationTestCase
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$hydrator->hydrateAll($stmt, $rsm);
}
public function testFetchJoinCollectionValuedAssociationWithDefaultArrayValue()
{
$rsm = new ResultSetMapping;
$rsm->addEntityResult(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, 'e1', null);
$rsm->addJoinedEntityResult(SimpleEntity::CLASSNAME, 'e2', 'e1', 'collection');
$rsm->addFieldResult('e1', 'a1__id', 'id');
$rsm->addFieldResult('e2', 'e2__id', 'id');
$result = (new ObjectHydrator($this->_em))
->hydrateAll(
new HydratorMockStatement([[
'a1__id' => '1',
'e2__id' => '1',
]]),
$rsm
);
$this->assertCount(1, $result);
$this->assertInstanceOf(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, $result[0]);
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0]->collection);
$this->assertCount(1, $result[0]->collection);
$this->assertInstanceOf(SimpleEntity::CLASSNAME, $result[0]->collection[0]);
}
}