Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-501

Merging entities that contained unloaded proxy collections will delete those associations

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP-Version 5.3.2
      PHPUnit-Version 3.4.11
      PDO Driver for MySQL, client library version => 5.0.83
      doctrine-trunk@7546
      Kubuntu 9.10 / 32bit

      Description

      If loading an entity without its -to-many-collections, detaching and merging it back WITHOUT having touched those associations will result in two strange behaviours:

      oneToMany (bidrectional, mapped by loaded entity): After merge the collection remains empty. Flushing EM and reloading entity will reveal associated entities again

      manyToMany (bidirectional, mapped by targeted entity): After merge the collection remains empty. Flushing EM will physically delete associations.

      • ----------------- !! NOTE !! --------------------
      • To reproduce the manyToMany-Bug it's necessary
      • to cascade "merge" on cmUser::groups
      • -------------------------------------------------

        Activity

        Hide
        Markus Wößner added a comment -

        Forgot to tell trunk revision

        Show
        Markus Wößner added a comment - Forgot to tell trunk revision
        Hide
        Christian Heinrich added a comment - - edited

        This issue is mainly caused by the entity not being initialized before serialization. Additionally, the PersistenCollection does loose all information that is needed to regain the kept entities because the collection itself is not initialized before serialization.

        I've added an initialization call here http://github.com/Shurakai/doctrine2/commit/6c185a2891111dfbd83d381bad8c5a2b16536cad#diff-0

        However, I'm not sure whether this is the best solution. Any thoughts?

        Show
        Christian Heinrich added a comment - - edited This issue is mainly caused by the entity not being initialized before serialization. Additionally, the PersistenCollection does loose all information that is needed to regain the kept entities because the collection itself is not initialized before serialization. I've added an initialization call here http://github.com/Shurakai/doctrine2/commit/6c185a2891111dfbd83d381bad8c5a2b16536cad#diff-0 However, I'm not sure whether this is the best solution. Any thoughts?
        Hide
        Roman S. Borschel added a comment -

        @Christian: I looked at the testcase you committed there and the assumptions it makes are not correct. The original test case provided by Markus made the right assumptions, that is, after the user is unserialized it can and should not know about its groups or phonenumbers since these were not serialized.
        When you serialize an entity, you serialize a partial snapshot of its state. When you unserialize it you have all the state that was loaded prior to serialization but you can not get at the rest, the object is detached from the rest of the object graph. Thats where merge() comes in, it reattaches a detached entity to a managed environment where associations can be lazy-loaded, state changes are tracked, etc.

        So the problem must come later, at the point of merging.

        Show
        Roman S. Borschel added a comment - @Christian: I looked at the testcase you committed there and the assumptions it makes are not correct. The original test case provided by Markus made the right assumptions, that is, after the user is unserialized it can and should not know about its groups or phonenumbers since these were not serialized. When you serialize an entity, you serialize a partial snapshot of its state. When you unserialize it you have all the state that was loaded prior to serialization but you can not get at the rest, the object is detached from the rest of the object graph. Thats where merge() comes in, it reattaches a detached entity to a managed environment where associations can be lazy-loaded, state changes are tracked, etc. So the problem must come later, at the point of merging.
        Hide
        Roman S. Borschel added a comment - - edited

        Pushing back to beta3.

        Show
        Roman S. Borschel added a comment - - edited Pushing back to beta3.
        Hide
        Benjamin Eberlei added a comment -

        Fixed.

        Show
        Benjamin Eberlei added a comment - Fixed.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Markus Wößner
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: