Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-875

Merge can sometimes add the same entity twice into a collection

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      When merging some cascade merge object-graphs, the same entity in a ManyToMany association can be put into a collection twice during doMerge.

      The attached patch should stop this from happening.

      1. multipleaddmerge.diff
        1 kB
        Dave Keen
      2. multipleaddmerge2.diff
        1 kB
        Dave Keen

        Activity

        Hide
        Alexander added a comment -

        We cannot reproduce this error and haven't had similar complaints ever-since. Feel free to open a new issue with a failing testcase.

        Show
        Alexander added a comment - We cannot reproduce this error and haven't had similar complaints ever-since. Feel free to open a new issue with a failing testcase.
        Hide
        Benjamin Eberlei added a comment -

        It seems even this issue is caused by multiple calls to persist. I cannot reproduce this with just a single bidirectional cascade merge.

        Show
        Benjamin Eberlei added a comment - It seems even this issue is caused by multiple calls to persist. I cannot reproduce this with just a single bidirectional cascade merge.
        Hide
        Dave Keen added a comment -

        Sorry, I am still getting the hang of git and diff and maybe what I put in there isn't what I meant to. I have now pushed the code to the DDC-875 branch on my ccapndave/doctrine2 fork on GitHub, hopefully this works better.

        As far as I can tell I am using unwrap() in order to check whether the element already exists in the array, but then calling >add() directly on the PersistentCollection rather than the ArrayCollection, triggering $this>changed().

        Show
        Dave Keen added a comment - Sorry, I am still getting the hang of git and diff and maybe what I put in there isn't what I meant to. I have now pushed the code to the DDC-875 branch on my ccapndave/doctrine2 fork on GitHub, hopefully this works better. As far as I can tell I am using unwrap() in order to check whether the element already exists in the array, but then calling >add() directly on the PersistentCollection rather than the ArrayCollection, triggering $this >changed().
        Hide
        Benjamin Eberlei added a comment - - edited

        That is exactly the same code in the patch, the lines are just formatted differently.

        Show
        Benjamin Eberlei added a comment - - edited That is exactly the same code in the patch, the lines are just formatted differently.
        Hide
        Dave Keen added a comment -

        Oops - that was a mistake. I have attached multipleaddmerge2.diff which no longer uses unwrap to add the element.

        Show
        Dave Keen added a comment - Oops - that was a mistake. I have attached multipleaddmerge2.diff which no longer uses unwrap to add the element.
        Hide
        Benjamin Eberlei added a comment -

        not doint the unwrap() but add() directly was a bugfix for one of your other issues .Why is unwrap in here again?

        Show
        Benjamin Eberlei added a comment - not doint the unwrap() but add() directly was a bugfix for one of your other issues .Why is unwrap in here again?
        Hide
        Benjamin Eberlei added a comment -

        which conditions lead to this problem? I want to write a test for it

        Show
        Benjamin Eberlei added a comment - which conditions lead to this problem? I want to write a test for it

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Dave Keen
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: