Compute entity change set in Doctrine
2 October 2025 (Updated 2 October 2025)
$unitOfWork = $this->entityManager->getUnitOfWork();
$unitOfWork->computeChangeSets();
$changeSet = $unitOfWork->getEntityChangeSet($client);
foreach ($changeSet as $fieldName => $changes) {
$oldValue = $changes[0];
$newValue = $changes[1];
dump(sprintf(
'The field "%s" changed from "%s" to "%s"',
$fieldName,
$oldValue,
$newValue,
));
}
Tagged:
Doctrine recipes