mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Redundant UPDATE queries from the second flush() in a row #6504
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 @develancer on GitHub (Jul 22, 2020).
Bug Report
Simple bi-directional OneToMany relation with auto-increment primary key makes UnitOfWork detect non-existing changes.
When performing two
flush()calls in a row, subsequent flush results in redundant UPDATE queries.Summary
Let's say we have a OneToMany relation between TestCollection and TestItem entities. Additionally, TestCollection has a single-column auto-increment primary key (IDENTITY GeneratedValue). We also have cascade persist and remove operations for items.
In a simplest scenario of creating a new collection with a single item
all seems fine, but if we add an additional
flush()just after the first one, it results in the additional UPDATE likeCurrent behavior
Subsequent
flush()operation results in a redundant UPDATE query. Internally, the UnitOfWork seems to detect a difference between$originalData['collection']which consist of an int(5) (!) and$actualData['collection']which is a proper entity.How to reproduce
TestItem:
TestCollection:
Database structure with an additional trigger to detect redundant UPDATE:
Expected behavior
Subsequent
flush()operation should perform no UPDATE queries.@Feolius commented on GitHub (Oct 17, 2021):
Having the same issue. However, I figured out that that problem also exists for OneToOne relationship, when foreign key is used as a primary key. Two test entities here:
The following codeblock
provides this output
So, we have redundant UPDATE query here, which is happening after the second flush() call.
@develancer commented on GitHub (Nov 26, 2021):
This bug is still present in 2.10.2, so I updated the specs.
@derrabus commented on GitHub (Dec 21, 2021):
@develancer Can you test #9244 please?
@develancer commented on GitHub (Dec 28, 2021):
@derrabus The patch does help. Thanks @Feolius