Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3101

Calling computeChangeSet twice generates invalid changeSet

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:

      Description

      Let's say I have an entity Answer and Question, the Question has two relations lastPost and solution. I also have a listener on preFlush for the Answer entity.

      When the entity is changed (or created), the listener is called and it finds lastPost and fills the relation in Question. The change was never persisted, so I've added $UoW->computeChangeSet() at the end of the listener over the changed Question instance. The documentation mentions it at onFlush event http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#preflush, but I figured it's probably the only way.

      So there we go, I have working form that I submit and the relation lastPost is always updated and propagated to database as expected.

      Now comes the problem.

      When I change the solution relation and the lastPost is updated from listener, the changeSet that was prepared is overriden and becase the computeChangeSet method overwrites the original UoW::$originalEntityData, the new computed changeSet is wrong and contains only the new lastPost and the changes made before last call to computeChangeSet are lost (they will not be saved to database).

      This is obviousely wrong and can be fixed either by not overwriting the originalEntityData property or by appending to changeSet (by fixing condition here https://github.com/doctrine/doctrine2/blob/35c8cd7f237a9a114303d14d573a28fb7d91b35e/lib/Doctrine/ORM/UnitOfWork.php#L624-L626 )

      Edit:
      I just figured it can be solved by using onFlush and recomputeSingleEntityChangeSet, but I really like the EntityListeners and they obviousely are not called on onFlush event.

        Activity

        Hide
        Filip Procházka added a comment -

        I still think this should be also doable in entity listener, but the bug appeared mostly becase of my bad usage...

        Show
        Filip Procházka added a comment - I still think this should be also doable in entity listener, but the bug appeared mostly becase of my bad usage...

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Filip Procházka
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: