Description
Bug Report
Q | A |
---|---|
BC Break | no |
Version | 2.7.0 but I guess reproducibly on 3.0 |
Summary
Using method computeChangeSets of class UnitOfWork, Im updating list of entities that going to be inserted/changed/deleted. At this point my entities still not flushed to database, but persisted to entityManager. After this, if I try to edit affected entity and flush - UnitOfWork runs computeChangeSets again and rewrites old change list ($this->entityChangeSets[$oid] in UnitOfWork). During flushing there are no enough data, so Im getting error like: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
, because old data was lost.
Current behavior
method computeChangeSets of class UnitOfWork rewrites old change list, even if entity was not flushed into db
How to reproduce
Create object of entity, persist to entityManager, call method computeChangeSets of class UnitOfWork, change something in object, call flush method of entityManager
Expected behavior
method computeChangeSets is public, so UnitOfWork must take it into account, because it can be used in client code. Method should not rewrites, but merge old and new entity change list.
Possible solution:
https://github.com/doctrine/orm/blob/3.0.x/lib/Doctrine/ORM/UnitOfWork.php#L715
Change:
if ($changeSet) {
$this->entityChangeSets[$oid] = $changeSet;
$this->originalEntityData[$oid] = $actualData;
$this->entityUpdates[$oid] = $entity;
}
To:
if ($changeSet) {
if (isset($this->entityChangeSets[$oid])) {
$newChangeSet = array_merge($this->entityChangeSets[$oid], $changeSet);
} else {
$newChangeSet = $changeSet;
}
$this->entityChangeSets[$oid] = $newChangeSet;
$this->originalEntityData[$oid] = $actualData;
$this->entityUpdates[$oid] = $entity;
}