Merge branch 'hotfix/#1387-DDC-3699-do-not-merge-managed-uninitialized-entities'
Close #1387
This commit is contained in:
commit
06a00cf073
@ -3393,7 +3393,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
} else {
|
||||
if ($other instanceof Proxy && !$other->__isInitialized()) {
|
||||
// do not merge fields marked lazy that have not been fetched.
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $assoc2['isCascadeMerge']) {
|
||||
@ -3421,7 +3421,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
if ($mergeCol instanceof PersistentCollection && ! $mergeCol->isInitialized()) {
|
||||
// do not merge fields marked lazy that have not been fetched.
|
||||
// keep the lazy persistent collection of the managed copy.
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
$managedCol = $prop->getValue($managedCopy);
|
||||
|
21
tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php
Normal file
21
tests/Doctrine/Tests/Models/DDC3699/DDC3699Child.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3699;
|
||||
|
||||
/** @Entity @Table(name="ddc3699_child") */
|
||||
class DDC3699Child extends DDC3699Parent
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
public $id;
|
||||
|
||||
/** @Column(type="string") */
|
||||
public $childField;
|
||||
|
||||
/** @OneToOne(targetEntity="DDC3699RelationOne", inversedBy="child") */
|
||||
public $oneRelation;
|
||||
|
||||
/** @OneToMany(targetEntity="DDC3699RelationMany", mappedBy="child") */
|
||||
public $relations;
|
||||
}
|
12
tests/Doctrine/Tests/Models/DDC3699/DDC3699Parent.php
Normal file
12
tests/Doctrine/Tests/Models/DDC3699/DDC3699Parent.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3699;
|
||||
|
||||
/** @MappedSuperclass */
|
||||
abstract class DDC3699Parent
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Column(type="string") */
|
||||
public $parentField;
|
||||
}
|
18
tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationMany.php
Normal file
18
tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationMany.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3699;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc3699_relation_many")
|
||||
*/
|
||||
class DDC3699RelationMany
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
public $id;
|
||||
|
||||
/** @ManyToOne(targetEntity="DDC3699Child", inversedBy="relations") */
|
||||
public $child;
|
||||
}
|
18
tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationOne.php
Normal file
18
tests/Doctrine/Tests/Models/DDC3699/DDC3699RelationOne.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Models\DDC3699;
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc3699_relation_one")
|
||||
*/
|
||||
class DDC3699RelationOne
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/** @Id @Column(type="integer") */
|
||||
public $id;
|
||||
|
||||
/** @OneToOne(targetEntity="DDC3699Child", mappedBy="oneRelation") */
|
||||
public $child;
|
||||
}
|
104
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php
Normal file
104
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3699Test.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
use Doctrine\DBAL\Schema\SchemaException;
|
||||
use Doctrine\Tests\Models\DDC3699\DDC3699Parent;
|
||||
use Doctrine\Tests\Models\DDC3699\DDC3699RelationOne;
|
||||
use Doctrine\Tests\Models\DDC3699\DDC3699RelationMany;
|
||||
use Doctrine\Tests\Models\DDC3699\DDC3699Child;
|
||||
|
||||
/**
|
||||
* @group DDC-3699
|
||||
*/
|
||||
class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('ddc3699');
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3699
|
||||
*/
|
||||
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToOneUninitializedAssociations()
|
||||
{
|
||||
$id = 1;
|
||||
|
||||
$child = new DDC3699Child();
|
||||
|
||||
$child->id = $id;
|
||||
$child->childField = 'childValue';
|
||||
$child->parentField = 'parentValue';
|
||||
|
||||
$relation = new DDC3699RelationOne();
|
||||
|
||||
$relation->id = $id;
|
||||
$relation->child = $child ;
|
||||
$child->oneRelation = $relation;
|
||||
|
||||
$this->_em->persist($relation);
|
||||
$this->_em->persist($child);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
// fixtures loaded
|
||||
/* @var $unManagedChild DDC3699Child */
|
||||
$unManagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||
|
||||
$this->_em->detach($unManagedChild);
|
||||
|
||||
// make it managed again
|
||||
$this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||
|
||||
$unManagedChild->childField = 'modifiedChildValue';
|
||||
$unManagedChild->parentField = 'modifiedParentValue';
|
||||
|
||||
/* @var $mergedChild DDC3699Child */
|
||||
$mergedChild = $this->_em->merge($unManagedChild);
|
||||
|
||||
$this->assertSame($mergedChild->childField, 'modifiedChildValue');
|
||||
$this->assertSame($mergedChild->parentField, 'modifiedParentValue');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3699
|
||||
*/
|
||||
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToManyUninitializedAssociations()
|
||||
{
|
||||
$id = 2;
|
||||
|
||||
$child = new DDC3699Child();
|
||||
|
||||
$child->id = $id;
|
||||
$child->childField = 'childValue';
|
||||
$child->parentField = 'parentValue';
|
||||
|
||||
$relation = new DDC3699RelationMany();
|
||||
|
||||
$relation->id = $id;
|
||||
$relation->child = $child ;
|
||||
$child->relations[] = $relation;
|
||||
|
||||
$this->_em->persist($relation);
|
||||
$this->_em->persist($child);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
/* @var $unmanagedChild DDC3699Child */
|
||||
$unmanagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||
$this->_em->detach($unmanagedChild);
|
||||
|
||||
// make it managed again
|
||||
$this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||
|
||||
$unmanagedChild->childField = 'modifiedChildValue';
|
||||
$unmanagedChild->parentField = 'modifiedParentValue';
|
||||
|
||||
/* @var $mergedChild DDC3699Child */
|
||||
$mergedChild = $this->_em->merge($unmanagedChild);
|
||||
|
||||
$this->assertSame($mergedChild->childField, 'modifiedChildValue');
|
||||
$this->assertSame($mergedChild->parentField, 'modifiedParentValue');
|
||||
}
|
||||
}
|
@ -139,6 +139,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
||||
'Doctrine\Tests\Models\DDC117\DDC117Editor',
|
||||
'Doctrine\Tests\Models\DDC117\DDC117Link',
|
||||
),
|
||||
'ddc3699' => array(
|
||||
'Doctrine\Tests\Models\DDC3699\DDC3699Parent',
|
||||
'Doctrine\Tests\Models\DDC3699\DDC3699RelationOne',
|
||||
'Doctrine\Tests\Models\DDC3699\DDC3699RelationMany',
|
||||
'Doctrine\Tests\Models\DDC3699\DDC3699Child',
|
||||
),
|
||||
'stockexchange' => array(
|
||||
'Doctrine\Tests\Models\StockExchange\Bond',
|
||||
'Doctrine\Tests\Models\StockExchange\Stock',
|
||||
|
Loading…
x
Reference in New Issue
Block a user