mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
onFlush event and $uow->computeChangeSets() in some cases erase entity properties #6246
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @forgie1 on GitHub (Jun 6, 2019).
Originally assigned to: @forgie1 on GitHub.
Bug Report
Summary
If in onFlush event is changed newly created entity property to the same value as it was before = basically no change happend, but property was set to the same value. Flush throws these different errors, it depends if property was scalar, or related object(s):
a)
INSERT INTO table (param1, param2, id) VALUES (?, ?, ?)' with params [1000]
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
b)
SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
Current behavior
parametes that have been set during onFlush event to the same value as they were originally (before onFlush event was invoked) are missing in changeset -> completely disappeared
How to reproduce
change new entity property in onFlush event to the same value as it was + call $uow->computeChangeSets()
in onFlush event:
$entity->getSize(); // 30
$entity->setSize(30);
$em->persist($entity);
$uow->computeChangeSets();
Expected behavior
Entity will be updated in DB with its proper values. Cahngeset will not be erased calling $uow->computeChangeSets() even if in onFlush event did set the same value to the entity property.
@SenseException commented on GitHub (Jun 11, 2019):
Have you tried the described
recomputeSingleEntityChangeSet()for changed primitives yet?https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/events.html#onflush