Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with tracking changes in associated relation #7365

Open
MassiveHiggsField opened this issue Aug 22, 2018 · 2 comments
Open

Problems with tracking changes in associated relation #7365

MassiveHiggsField opened this issue Aug 22, 2018 · 2 comments

Comments

@MassiveHiggsField
Copy link

Q A
Version v2.6.2

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:

foreach ($unitOfWork->getScheduledCollectionDeletions() as $delete) {
    /** @var PersistentCollection $delete */
    $insertDiffDeletions = $delete->getInsertDiff();
    $deleteDiffDeletions = $delete->getDeleteDiff();
    ...
}
foreach ($unitOfWork->getScheduledCollectionUpdates() as $update) {
    /** @var PersistentCollection $update */
    $insertDiffUpdates = $update->getInsertDiff();
    $deleteDiffUpdates = $update->getDeleteDiff();
    ...
}

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?

  • getScheduledCollectionDeletions is empty
  • getScheduledCollectionUpdates has one entry
    • $update->getInsertDiff() is empty
    • $update->getDeleteDiff() has one entry

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?

  • getScheduledCollectionDeletions is empty
  • getScheduledCollectionUpdates has one entry
    • $update->getInsertDiff() has one entry
    • $update->getDeleteDiff() is empty

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?

  • getScheduledCollectionDeletions is empty
  • getScheduledCollectionUpdates is empty

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?

  • getScheduledCollectionDeletions is empty
  • getScheduledCollectionUpdates has one entry
    • $update->getInsertDiff() has one entry
    • $update->getDeleteDiff() is empty

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?

  • getScheduledCollectionDeletions is empty
  • getScheduledCollectionUpdates has one entry
    • $update->getInsertDiff() is empty
    • $update->getDeleteDiff() has one entry

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
Copy link

Same problem!! Since 2018? :(

@mrtnzagustin
Copy link

@DamienHarper are you aware of this? i was checking your code at https://github.com/DamienHarper/auditor/blob/6843e885518a1d8b61868fc0ba36a257a28ad828/src/Provider/Doctrine/Auditing/Transaction/TransactionHydrator.php to create a logger for a legacy migration with tables that have composite keys everywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants