Get entity change sets - do not change internal unit of work state #5493

Open
opened 2026-01-22 15:09:05 +01:00 by admin · 0 comments
Owner

Originally created by @vasekjares on GitHub (Apr 6, 2017).

Originally assigned to: @Ocramius on GitHub.

It would be great to have a method to get entity change set without changing internal unit of work state:

$user = $em->find(User::class, 1);
$user->setAge(10);
$user->setName('John');
$em->getUnitOfWork()->recomputeChangeSets();
$logger->log(User::class, 1, $em->getUnitOfWork()->getEntityChangeSet($user));
$em->flush();

Code above works great, but issue is that it changes internal state of UoW. (updates original snapshots). So if I change code to:

$user = $em->find(User::class, 1);
$user->setAge(10);
$user->setName('John');
$em->getUnitOfWork()->recomputeChangeSets();
$logger->log(User::class, 1, $em->getUnitOfWork()->getEntityChangeSet($user));
$user->setEnabled(true); //previous value was false
$em->flush();

Only "enabled" property is persisted. Changes of age and name are forgotten (unless I recompute change sets manually again)

It would be great to have method which just calculates change sets and returns them (with not internal changes to UoW)

Originally created by @vasekjares on GitHub (Apr 6, 2017). Originally assigned to: @Ocramius on GitHub. It would be great to have a method to get entity change set without changing internal unit of work state: `$user = $em->find(User::class, 1);` `$user->setAge(10);` `$user->setName('John');` `$em->getUnitOfWork()->recomputeChangeSets();` `$logger->log(User::class, 1, $em->getUnitOfWork()->getEntityChangeSet($user));` `$em->flush();` Code above works great, but issue is that it changes internal state of UoW. (updates original snapshots). So if I change code to: `$user = $em->find(User::class, 1);` `$user->setAge(10);` `$user->setName('John');` `$em->getUnitOfWork()->recomputeChangeSets();` `$logger->log(User::class, 1, $em->getUnitOfWork()->getEntityChangeSet($user));` `$user->setEnabled(true); //previous value was false` `$em->flush();` Only "enabled" property is persisted. Changes of age and name are forgotten (unless I recompute change sets manually again) It would be great to have method which just calculates change sets and returns them (with not internal changes to UoW)
admin added the New FeatureWon't Fix labels 2026-01-22 15:09:05 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5493