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