DDC-1129: UnitOfWork consider version field changed as entity changed #1417

Closed
opened 2026-01-22 13:13:41 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 28, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user realmfoo:

I use @version field and after first save it thinks that versionField was changed.

$Entity = $em->find(...);
$Entity->changeField();
$em->persist($Entity);
$em->flush();
$em->getUnitOfWork()->computeChangeSets();
var_dump($em->getUnitOfWork()->getEntityChangeSet($Entity);
array(1) {
  ["version"]=>
  array(2) {
    [0]=>
    int(183)
    [1]=>
    int(184)
  }
}

I fixed it in method computeChangeSet on lines around 473:

Index: ../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php
===================================================================
@@ -448,6 <ins>448,9 @@
             $changeSet = $isChangeTrackingNotify ? $this->entityChangeSets[$oid] : array();

             foreach ($actualData as $propName => $actualValue) {
</ins>                if ($class->isVersioned && $propName == $class->versionField) {
<ins>                    continue;
</ins>                }
                 $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null;
                 if (isset($class->associationMappings[$propName])) {
                     $assoc = $class->associationMappings[$propName];
Originally created by @doctrinebot on GitHub (Apr 28, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user realmfoo: I use @version field and after first save it thinks that versionField was changed. ``` $Entity = $em->find(...); $Entity->changeField(); $em->persist($Entity); $em->flush(); $em->getUnitOfWork()->computeChangeSets(); var_dump($em->getUnitOfWork()->getEntityChangeSet($Entity); ``` ``` array(1) { ["version"]=> array(2) { [0]=> int(183) [1]=> int(184) } } ``` I fixed it in method computeChangeSet on lines around 473: ``` Index: ../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php =================================================================== @@ -448,6 <ins>448,9 @@ $changeSet = $isChangeTrackingNotify ? $this->entityChangeSets[$oid] : array(); foreach ($actualData as $propName => $actualValue) { </ins> if ($class->isVersioned && $propName == $class->versionField) { <ins> continue; </ins> } $orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null; if (isset($class->associationMappings[$propName])) { $assoc = $class->associationMappings[$propName]; ```
admin added the Bug label 2026-01-22 13:13:41 +01:00
admin closed this issue 2026-01-22 13:13:43 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 30, 2011):

Comment created by @beberlei:

The fix is bad. There is a much better way, but i can confirm this issue exists.

@doctrinebot commented on GitHub (Apr 30, 2011): Comment created by @beberlei: The fix is bad. There is a much better way, but i can confirm this issue exists.
Author
Owner

@doctrinebot commented on GitHub (May 1, 2011):

Comment created by @beberlei:

Fixed.

@doctrinebot commented on GitHub (May 1, 2011): Comment created by @beberlei: Fixed.
Author
Owner

@doctrinebot commented on GitHub (May 1, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 1, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1417