Skip to content

Commit fdd5f6a

Browse files
committed
fix(GH12017): Ignore non-updatable and non-insertable fields from corresponding changesets
1 parent f1fddb3 commit fdd5f6a

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/UnitOfWork.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void
586586
$this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke);
587587
}
588588

589+
$isNew = ! isset($this->originalEntityData[$oid]);
589590
$actualData = [];
590591

591592
foreach ($class->propertyAccessors as $name => $refProp) {
@@ -626,18 +627,26 @@ public function computeChangeSet(ClassMetadata $class, object $entity): void
626627
}
627628

628629
if (( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) && ($name !== $class->versionField)) {
630+
if (! $isNew && isset($class->fieldMappings[$name]->notUpdatable)) {
631+
continue;
632+
}
633+
629634
$actualData[$name] = $value;
630635
}
631636
}
632637

633-
if (! isset($this->originalEntityData[$oid])) {
638+
if ($isNew) {
634639
// Entity is either NEW or MANAGED but not yet fully persisted (only has an id).
635640
// These result in an INSERT.
636641
$this->originalEntityData[$oid] = $actualData;
637642
$changeSet = [];
638643

639644
foreach ($actualData as $propName => $actualValue) {
640645
if (! isset($class->associationMappings[$propName])) {
646+
if (isset($class->fieldMappings[$propName]->notInsertable)) {
647+
continue;
648+
}
649+
641650
$changeSet[$propName] = [null, $actualValue];
642651

643652
continue;
@@ -990,6 +999,7 @@ public function recomputeSingleEntityChangeSet(ClassMetadata $class, object $ent
990999
( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity())
9911000
&& ($name !== $class->versionField)
9921001
&& ! $class->isCollectionValuedAssociation($name)
1002+
&& ! isset($class->fieldMappings[$name]->notUpdatable)
9931003
) {
9941004
$actualData[$name] = $refProp->getValue($entity);
9951005
}

0 commit comments

Comments
 (0)