Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa3916c

Browse files
committed
Fix original data incomplete after flush
1 parent 40d1e7b commit fa3916c

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

lib/Doctrine/ORM/UnitOfWork.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ public function computeChangeSet(ClassMetadata $class, $entity)
658658
if ($class->isCollectionValuedAssociation($name) && $value !== null) {
659659
if ($value instanceof PersistentCollection) {
660660
if ($value->getOwner() === $entity) {
661+
$actualData[$name] = $value;
661662
continue;
662663
}
663664

tests/Doctrine/Tests/ORM/UnitOfWorkTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,75 @@ public function testItThrowsWhenLookingUpIdentifierForUnknownEntity(): void
828828
$this->expectException(EntityNotFoundException::class);
829829
$this->_unitOfWork->getEntityIdentifier(new stdClass());
830830
}
831+
832+
/**
833+
* @group #9300
834+
*/
835+
public function testPersistedCollectionIsPresentInOriginalDataAfterComputeChangeset(): void
836+
{
837+
$entity = new EntityWithCollection();
838+
$entity->children->add(new ChildEntity());
839+
$entity->name = 'abc';
840+
841+
$this->_unitOfWork->persist($entity);
842+
$this->_unitOfWork->commit();
843+
844+
$entity->name = 'abcd';
845+
$this->_unitOfWork->computeChangeSets();
846+
847+
self::assertArrayHasKey('children', $this->_unitOfWork->getOriginalEntityData($entity));
848+
}
849+
}
850+
851+
/**
852+
* @Entity
853+
*/
854+
class EntityWithCollection
855+
{
856+
/**
857+
* @var Collection|ChildEntity[]
858+
* @OneToMany(targetEntity="ChildEntity", mappedBy="parent", cascade={"persist"})
859+
*/
860+
public $children;
861+
862+
/**
863+
* @var int
864+
* @Id
865+
* @Column(type="integer")
866+
* @GeneratedValue
867+
*/
868+
public $id;
869+
870+
/**
871+
* @var string
872+
* @Column(type="string")
873+
*/
874+
public $name;
875+
876+
public function __construct()
877+
{
878+
$this->children = new ArrayCollection();
879+
}
880+
}
881+
882+
/**
883+
* @Entity
884+
*/
885+
class ChildEntity
886+
{
887+
/**
888+
* @var int
889+
* @Id
890+
* @Column(type="integer")
891+
* @GeneratedValue
892+
*/
893+
public $id;
894+
895+
/**
896+
* @var int
897+
* @ManyToOne(targetEntity="EntityWithCollection", inversedBy="children")
898+
*/
899+
public $parent;
831900
}
832901

833902
/**

0 commit comments

Comments
 (0)