Skip to content

Commit

Permalink
Fix original data incomplete after flush
Browse files Browse the repository at this point in the history
  • Loading branch information
olsavmic committed Dec 29, 2021
1 parent 40d1e7b commit fa3916c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ public function computeChangeSet(ClassMetadata $class, $entity)
if ($class->isCollectionValuedAssociation($name) && $value !== null) {
if ($value instanceof PersistentCollection) {
if ($value->getOwner() === $entity) {
$actualData[$name] = $value;
continue;
}

Expand Down
69 changes: 69 additions & 0 deletions tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,75 @@ public function testItThrowsWhenLookingUpIdentifierForUnknownEntity(): void
$this->expectException(EntityNotFoundException::class);
$this->_unitOfWork->getEntityIdentifier(new stdClass());
}

/**
* @group #9300
*/
public function testPersistedCollectionIsPresentInOriginalDataAfterComputeChangeset(): void
{
$entity = new EntityWithCollection();
$entity->children->add(new ChildEntity());
$entity->name = 'abc';

$this->_unitOfWork->persist($entity);
$this->_unitOfWork->commit();

$entity->name = 'abcd';
$this->_unitOfWork->computeChangeSets();

self::assertArrayHasKey('children', $this->_unitOfWork->getOriginalEntityData($entity));
}
}

/**
* @Entity
*/
class EntityWithCollection
{
/**
* @var Collection|ChildEntity[]
* @OneToMany(targetEntity="ChildEntity", mappedBy="parent", cascade={"persist"})
*/
public $children;

/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;

/**
* @var string
* @Column(type="string")
*/
public $name;

public function __construct()
{
$this->children = new ArrayCollection();
}
}

/**
* @Entity
*/
class ChildEntity
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;

/**
* @var int
* @ManyToOne(targetEntity="EntityWithCollection", inversedBy="children")
*/
public $parent;
}

/**
Expand Down

0 comments on commit fa3916c

Please sign in to comment.