mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Problems with tracking changes in associated relation #6044
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 @MassiveHiggsField on GitHub (Aug 22, 2018).
Support Question
So, i've been trying to track changes to an associated relation in an onflush listener.
I'm using this code to check for changes:
But the results seem to be inconsistent or not usable. Here are my findings:
Scenario: My associated list has three items in it
Case 1: What happens if i remove one item from the association?
This seems a litte bit weird, i would expect getScheduledCollectionDeletions would have the entry, but fine, i can work with this (i've also tried removing two items, which also worked and getDeleteDiff had two entries).
Case 2: What happens if i add one item to the association?
This would be as expected (i've also tried adding two items, which also worked and getInsertDiff had two entries)
Case 3: What happens if i add one item and remove one item from the association?
This cannot be right. There seems to be no way to find out that this list has been changed.
Case 4: What happens if i add two items and remove one item from the association?
Once again, this cant be right. Only one addition is tracked.
Case 5: What happens if i add one item and remove two items from the association?
Once again, doesnt seem to be right. Only one deletion is tracked.
So, i cant figure out how to track all changes to the associated list. Any help appreciated? Maybe this is even a bug. It seems to me the getScheduledCollectionUpdates calculates changes by comparing the list length before and after, not really comparing the changes to the list.
@mrtnzagustin commented on GitHub (Oct 6, 2021):
Same problem!! Since 2018? :(
@mrtnzagustin commented on GitHub (Oct 6, 2021):
@DamienHarper are you aware of this? i was checking your code at
6843e88551/src/Provider/Doctrine/Auditing/Transaction/TransactionHydrator.phpto create a logger for a legacy migration with tables that have composite keys everywhere@mmarton commented on GitHub (May 7, 2025):
Still an issue in 2025, since 2013
https://stackoverflow.com/questions/15311083/whats-the-proper-use-of-unitofwork-getscheduledcollectiondeletions-in-doctr