Hydration of fetch-joined results fails when an entity has a default value of array
for the collection property
This commit is contained in:
parent
34696126e0
commit
a1602bd91f
@ -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 = [];
|
||||||
|
}
|
12
tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php
Normal file
12
tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php
Normal 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;
|
||||||
|
}
|
@ -8,6 +8,8 @@ use Doctrine\ORM\Proxy\ProxyFactory;
|
|||||||
use Doctrine\ORM\Mapping\AssociationMapping;
|
use Doctrine\ORM\Mapping\AssociationMapping;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
|
use Doctrine\Tests\Models\Hydration\EntityWithArrayDefaultArrayValueM2M;
|
||||||
|
use Doctrine\Tests\Models\Hydration\SimpleEntity;
|
||||||
|
|
||||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||||
|
|
||||||
@ -1956,4 +1958,29 @@ class ObjectHydratorTest extends HydrationTestCase
|
|||||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||||
$hydrator->hydrateAll($stmt, $rsm);
|
$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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user