Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2033

Merge with multiple Associations to the same Entity


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
    • Environment:
      Symfony 2.1.1, Ubuntu, PHP 5.3.5


      Let's say we have 2 Entities. User and Group and there's a ManyToMany Assocication and an additional ManyToOne (User as owning side and no inverse).

      So a User can have as many Groups as he likes and one another with the ManyToOne Association which can be also in the ManyToMany Collection. (Could be the MainGroup or something)

      I create a User and add a Group(already in DB) and set the same as the ManyToOne and Merge it. Everything works fine as long as the Group in ManyToOne Association is not in the ManyToMany.

      If I var_dump the merged entity i can already see that one association is empty.

      It looks like doctrine is writing just one association of that Group preferring which one comes first. So if i change the position of the properties in the class the written association changes, but doctrine never writes both.

      The reason why I use merge is that I normally store the entity in the session and merge and flush it in another request. But this also happens in the same Request.

      In the UnitofWork at Line 2050 and 2053 are the responsible doMerge Calls for as CascadeMerge Tagged Associations. If Doctrine gets there in the first place the doMerge for the Group is running through. In the Second call when the Group is again associated with the user the doMerge already exits at line 1658. That's ok but I think there's something missing so doctrine isn't creating the association.

      The Mentioned Entites are attached

      1. Group.php
        0.5 kB
        sören jahns
      2. User.php
        0.9 kB
        sören jahns



          • Assignee:
            Marco Pivetta
            sören jahns
          • Votes:
            1 Vote for this issue
            2 Start watching this issue


            • Created: