diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index a07abb49c7f..fa0ae38eed1 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2216,12 +2216,12 @@ private function doRefresh($entity, array &$visited): void throw ORMInvalidArgumentException::entityNotManaged($entity); } + $this->cascadeRefresh($entity, $visited); + $this->getEntityPersister($class->name)->refresh( array_combine($class->getIdentifierFieldNames(), $this->entityIdentifiers[$oid]), $entity ); - - $this->cascadeRefresh($entity, $visited); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH4252Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH4252Test.php index efd7802674f..82927651473 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH4252Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH4252Test.php @@ -1,27 +1,39 @@ _schemaTool->createSchema(array( + $this->_schemaTool->createSchema([ $this->_em->getClassMetadata(GH4252City::class), $this->_em->getClassMetadata(GH4252Resident::class), $this->_em->getClassMetadata(GH4252Address::class), - )); + ]); } - public function testIssue() + public function testIssue(): void { $city = new GH4252City([new GH4252Resident([new GH4252Address()])]); @@ -29,20 +41,20 @@ public function testIssue() $this->_em->flush(); $this->_em->clear(); - /** @var GH4252City $city */ $city = $this->_em->find(GH4252City::class, $city->getId()); + assert($city instanceof GH4252City); $city->setFlag(false); - /** @var GH4252Resident $resident */ $resident = $city->getResidents()->first(); + assert($resident instanceof GH4252Resident); $resident->setFlag(false); - /** @var GH4252Address $address */ $address = $resident->getAddresses()->first(); + assert($address instanceof GH4252Address); $address->setFlag(false); $this->_em->refresh($city); $resident = $city->getResidents()->first(); - $address = $resident->getAddresses()->first(); + $address = $resident->getAddresses()->first(); $this->assertTrue($city->getFlag()); $this->assertTrue($resident->getFlag()); @@ -57,7 +69,9 @@ class GH4252City { /** * @var int - * @Id @Column(type="integer") @GeneratedValue + * @Id + * @Column(type="integer") + * @GeneratedValue */ private $id; @@ -69,7 +83,6 @@ class GH4252City /** * @var GH4252Resident[]|Collection - * * @OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Resident", mappedBy="city", cascade={"persist","refresh"}) */ private $residents; @@ -81,25 +94,26 @@ public function __construct(array $residents) $this->residents->add($resident); $resident->setCity($this); } + $this->flag = true; } - public function getId() : int + public function getId(): int { return $this->id; } - public function getFlag() : bool + public function getFlag(): bool { return $this->flag; } - public function setFlag(bool $flag) : void + public function setFlag(bool $flag): void { $this->flag = $flag; } - public function getResidents() : Collection + public function getResidents(): Collection { return $this->residents; } @@ -130,7 +144,6 @@ class GH4252Resident /** * @var GH4252Address[]|Collection - * * @ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Address", fetch="EXTRA_LAZY", cascade={"persist","refresh"}) */ private $addresses; @@ -141,35 +154,36 @@ public function __construct(array $addresses) foreach ($addresses as $address) { $this->addresses->add($address); } + $this->flag = true; } - public function getId() : int + public function getId(): int { return $this->id; } - public function getCity() : GH4252City + public function getCity(): GH4252City { return $this->city; } - public function setCity(GH4252City $city) : void + public function setCity(GH4252City $city): void { $this->city = $city; } - public function getFlag() : bool + public function getFlag(): bool { return $this->flag; } - public function setFlag(bool $flag) : void + public function setFlag(bool $flag): void { $this->flag = $flag; } - public function getAddresses() : Collection + public function getAddresses(): Collection { return $this->addresses; } @@ -180,7 +194,9 @@ class GH4252Address { /** * @var int - * @Id @Column(type="integer") @GeneratedValue + * @Id + * @Column(type="integer") + * @GeneratedValue */ private $id; @@ -195,17 +211,17 @@ public function __construct() $this->flag = true; } - public function getId() : int + public function getId(): int { return $this->id; } - public function getFlag() : bool + public function getFlag(): bool { return $this->flag; } - public function setFlag(bool $flag) : void + public function setFlag(bool $flag): void { $this->flag = $flag; }