Merge branch 'fix/#6004-#5989-fix-hydration-in-a-joined-inheritance-with-simple-array-or-json-array-2.5' into 2.5
Close #6004 Close #5989
This commit is contained in:
commit
d592c14a6c
@ -122,6 +122,9 @@ class SimpleObjectHydrator extends AbstractHydrator
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if value is null before conversion (because some types convert null to something else)
|
||||||
|
$valueIsNull = null === $value;
|
||||||
|
|
||||||
// Convert field to a valid PHP value
|
// Convert field to a valid PHP value
|
||||||
if (isset($cacheKeyInfo['type'])) {
|
if (isset($cacheKeyInfo['type'])) {
|
||||||
$type = $cacheKeyInfo['type'];
|
$type = $cacheKeyInfo['type'];
|
||||||
@ -131,7 +134,7 @@ class SimpleObjectHydrator extends AbstractHydrator
|
|||||||
$fieldName = $cacheKeyInfo['fieldName'];
|
$fieldName = $cacheKeyInfo['fieldName'];
|
||||||
|
|
||||||
// Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator)
|
// Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator)
|
||||||
if ( ! isset($data[$fieldName]) || $value !== null) {
|
if ( ! isset($data[$fieldName]) || ! $valueIsNull) {
|
||||||
$data[$fieldName] = $value;
|
$data[$fieldName] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php
Normal file
17
tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\Issue5989;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="issue5989_employees")
|
||||||
|
*/
|
||||||
|
class Issue5989Employee extends Issue5989Person
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Column(type="simple_array", nullable=true)
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $tags;
|
||||||
|
}
|
17
tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php
Normal file
17
tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\Issue5989;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="issue5989_managers")
|
||||||
|
*/
|
||||||
|
class Issue5989Manager extends Issue5989Person
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Column(type="simple_array", nullable=true)
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $tags;
|
||||||
|
}
|
24
tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php
Normal file
24
tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\Issue5989;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="issue5989_persons")
|
||||||
|
* @InheritanceType("JOINED")
|
||||||
|
* @DiscriminatorColumn(name="discr", type="string")
|
||||||
|
* @DiscriminatorMap({
|
||||||
|
* "person" = "Issue5989Person",
|
||||||
|
* "manager" = "Issue5989Manager",
|
||||||
|
* "employee" = "Issue5989Employee"
|
||||||
|
* })
|
||||||
|
*/
|
||||||
|
class Issue5989Person
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer")
|
||||||
|
* @GeneratedValue
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
}
|
51
tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php
Normal file
51
tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\Tests\Models\Issue5989\Issue5989Employee;
|
||||||
|
use Doctrine\Tests\Models\Issue5989\Issue5989Manager;
|
||||||
|
use Doctrine\Tests\Models\Issue5989\Issue5989Person;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group issue-5989
|
||||||
|
*/
|
||||||
|
class Issue5989Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->useModelSet('issue5989');
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSimpleArrayTypeHydratedCorrectlyInJoinedInheritance()
|
||||||
|
{
|
||||||
|
$manager = new Issue5989Manager();
|
||||||
|
|
||||||
|
$managerTags = ['tag1', 'tag2'];
|
||||||
|
$manager->tags = $managerTags;
|
||||||
|
$this->_em->persist($manager);
|
||||||
|
|
||||||
|
$employee = new Issue5989Employee();
|
||||||
|
|
||||||
|
$employeeTags =['tag2', 'tag3'];
|
||||||
|
$employee->tags = $employeeTags;
|
||||||
|
$this->_em->persist($employee);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$managerId = $manager->id;
|
||||||
|
$employeeId = $employee->id;
|
||||||
|
|
||||||
|
// clear entity manager so that $repository->find actually fetches them and uses the hydrator
|
||||||
|
// instead of just returning the existing managed entities
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$repository = $this->_em->getRepository(Issue5989Person::class);
|
||||||
|
|
||||||
|
$manager = $repository->find($managerId);
|
||||||
|
$employee = $repository->find($employeeId);
|
||||||
|
|
||||||
|
static::assertEquals($managerTags, $manager->tags);
|
||||||
|
static::assertEquals($employeeTags, $employee->tags);
|
||||||
|
}
|
||||||
|
}
|
@ -86,4 +86,34 @@ class SimpleObjectHydratorTest extends HydrationTestCase
|
|||||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
||||||
$hydrator->hydrateAll($stmt, $rsm);
|
$hydrator->hydrateAll($stmt, $rsm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group issue-5989
|
||||||
|
*/
|
||||||
|
public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInheritance()
|
||||||
|
{
|
||||||
|
$rsm = new ResultSetMapping;
|
||||||
|
$rsm->addEntityResult('Doctrine\Tests\Models\Issue5989\Issue5989Person', 'p');
|
||||||
|
$rsm->addFieldResult('p', 'p__id', 'id');
|
||||||
|
$rsm->addFieldResult('p', 'm__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager');
|
||||||
|
$rsm->addFieldResult('p', 'e__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee');
|
||||||
|
$rsm->addMetaResult('p', 'discr', 'discr', false, 'string');
|
||||||
|
$resultSet = array(
|
||||||
|
array(
|
||||||
|
'p__id' => '1',
|
||||||
|
'm__tags' => 'tag1,tag2',
|
||||||
|
'e__tags' => null,
|
||||||
|
'discr' => 'manager'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$expectedEntity = new \Doctrine\Tests\Models\Issue5989\Issue5989Manager();
|
||||||
|
$expectedEntity->id = 1;
|
||||||
|
$expectedEntity->tags = ['tag1', 'tag2'];
|
||||||
|
|
||||||
|
$stmt = new HydratorMockStatement($resultSet);
|
||||||
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
||||||
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
||||||
|
$this->assertEquals($result[0], $expectedEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,6 +284,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
'Doctrine\Tests\Models\VersionedManyToOne\Category',
|
'Doctrine\Tests\Models\VersionedManyToOne\Category',
|
||||||
'Doctrine\Tests\Models\VersionedManyToOne\Article',
|
'Doctrine\Tests\Models\VersionedManyToOne\Article',
|
||||||
),
|
),
|
||||||
|
'issue5989' => array(
|
||||||
|
'Doctrine\Tests\Models\Issue5989\Issue5989Person',
|
||||||
|
'Doctrine\Tests\Models\Issue5989\Issue5989Employee',
|
||||||
|
'Doctrine\Tests\Models\Issue5989\Issue5989Manager',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -544,6 +549,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
$conn->executeUpdate('DELETE FROM versioned_many_to_one_category');
|
$conn->executeUpdate('DELETE FROM versioned_many_to_one_category');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($this->_usedModelSets['issue5989'])) {
|
||||||
|
$conn->executeUpdate('DELETE FROM issue5989_persons');
|
||||||
|
$conn->executeUpdate('DELETE FROM issue5989_employees');
|
||||||
|
$conn->executeUpdate('DELETE FROM issue5989_managers');
|
||||||
|
}
|
||||||
|
|
||||||
$this->_em->clear();
|
$this->_em->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user