Skip to content

Commit

Permalink
Store PersistentCollection changes in entity change set as array
Browse files Browse the repository at this point in the history
The property $entityChangeSets of UnitOfWork stores entity changes
as an array of two items for each property changed. Before this
change, when an entity with a property holding a Collection was
changed, $entityChangeSets stored only the old Collection.
  • Loading branch information
franmomu committed Nov 20, 2023
1 parent 2c06ffa commit ec9f131
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ Use one of the dedicated event classes instead:
* `Doctrine\ORM\Event\PostRemoveEventArgs`
* `Doctrine\ORM\Event\PostLoadEventArgs`

## BC BREAK: Changed entity changeset when a `Collection` is modified

When working with an entity with a `Collection` property, when that property
is changed, the changeset stored in `UnitOfWork` includes the old and the new
value of this property as an array of two items.

## BC BREAK: Removed `AttributeDriver::$entityAnnotationClasses` and `AttributeDriver::getReader()`

* If you need to change the behavior of `AttributeDriver::isTransient()`,
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/ORM/Event/PreUpdateEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\ORM\Event;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\PersistentCollection;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use InvalidArgumentException;

Expand All @@ -19,12 +18,12 @@
*/
class PreUpdateEventArgs extends LifecycleEventArgs
{
/** @var array<string, array{mixed, mixed}|PersistentCollection> */
/** @var array<string, array{mixed, mixed}> */
private array $entityChangeSet;

/**
* @param mixed[][] $changeSet
* @psalm-param array<string, array{mixed, mixed}|PersistentCollection> $changeSet
* @psalm-param array<string, array{mixed, mixed}> $changeSet
*/
public function __construct(object $entity, EntityManagerInterface $em, array &$changeSet)
{
Expand All @@ -37,7 +36,7 @@ public function __construct(object $entity, EntityManagerInterface $em, array &$
* Retrieves entity changeset.
*
* @return mixed[][]
* @psalm-return array<string, array{mixed, mixed}|PersistentCollection>
* @psalm-return array<string, array{mixed, mixed}>
*/
public function getEntityChangeSet(): array
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ private function executeExtraUpdates(): void
* Gets the changeset for an entity.
*
* @return mixed[][]
* @psalm-return array<string, array{mixed, mixed}|PersistentCollection>
* @psalm-return array<string, array{mixed, mixed}>
*/
public function & getEntityChangeSet(object $entity): array
{
Expand Down Expand Up @@ -715,7 +715,7 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void
}

$this->collectionDeletions[$coid] = $orgValue;
$changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored.
$changeSet[$propName] = [$orgValue, $actualValue];

continue;
}
Expand Down
6 changes: 1 addition & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,7 @@
<code>$collectionToDelete</code>
<code>$collectionToUpdate</code>
</InvalidArgument>
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->entityChangeSets]]></code>
<code><![CDATA[$this->entityChangeSets]]></code>
</InvalidPropertyAssignmentValue>
<NoValue>
<NoValue occurrences="2">
<code>$entityState</code>
<code>$entityState</code>
</NoValue>
Expand Down

0 comments on commit ec9f131

Please sign in to comment.