Doctrine MongoDB ODM
  1. Doctrine MongoDB ODM
  2. MODM-79

Referenced and Embedded document duplicates are inserted

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.0BETA2
    • Component/s: Persister
    • Labels:
      None

      Description

      I have a document with several collections referencing documents in other collections.

      Doctrine ODM seems to have issues with ArrayCollections and realizing that elements are being taken out. I call ArrayCollection->clear() on those collections but when calculating the changeset Doctrine does not realize that some were deleted.

      My scenario is following: I have a REST API. On the API I use Doctrine ODM as data backend.

      Now when I get a request to update an object, I get the passed ID of the object, and populate all the fields.

      However with collections I call clear() on the collection and then re-add all passed elements. This might not be a very elegant solution, but I don't have to worry about added / changed / deleted items. I pretty much just set a new collection.

      However, when persisting this document, Doctrine does not seem to notice that I cleared the collection. It just adds all the objects I added to the collection. Therefore I have a lot of duplicate items in my collection.

        Activity

        Hide
        Alexander Koß added a comment - - edited

        i have the same problem.
        when i flush persistant data i get duplicated entries.

        $this->_dm->persist($Opinion);
        $this->_dm->flush();

        Show
        Alexander Koß added a comment - - edited i have the same problem. when i flush persistant data i get duplicated entries. $this->_dm->persist($Opinion); $this->_dm->flush();
        Hide
        Ryan Weaver added a comment -

        I believe I'm replicating this issue and have a test case for it here: http://github.com/weaverryan/mongodb-odm/commit/9968697a2c07e31ecfdd8d55ecbf9bf39183d01e

        The second test case, testReplaceEntireGroupsArray() displays the above error. The update contains a pushAll() for the one embedded document that remains, but no pullAll() to remove the embedded documents that no longer exist.

        The first test case, testModifyGroupsArrayDirectly() tests for a different, related issue. I'll open a separate ticket for it.

        Thanks

        Show
        Ryan Weaver added a comment - I believe I'm replicating this issue and have a test case for it here: http://github.com/weaverryan/mongodb-odm/commit/9968697a2c07e31ecfdd8d55ecbf9bf39183d01e The second test case, testReplaceEntireGroupsArray() displays the above error. The update contains a pushAll() for the one embedded document that remains, but no pullAll() to remove the embedded documents that no longer exist. The first test case, testModifyGroupsArrayDirectly() tests for a different, related issue. I'll open a separate ticket for it. Thanks
        Hide
        Sebastian Hoitz added a comment -

        It looks like the changeset is calculated correctly.
        So there must be a fault afterwards.

        Maybe it has to do with MongoDB's limitation of just sending one atomic operator on one field at a time?

        Can we use a $set on a collection? Or don't we do this because we would also re-send unmodified entries?

        Show
        Sebastian Hoitz added a comment - It looks like the changeset is calculated correctly. So there must be a fault afterwards. Maybe it has to do with MongoDB's limitation of just sending one atomic operator on one field at a time? Can we use a $set on a collection? Or don't we do this because we would also re-send unmodified entries?
        Hide
        Sebastian Hoitz added a comment -
        Show
        Sebastian Hoitz added a comment - This commit fixed the issue for me: http://github.com/doctrine/mongodb-odm/commit/6b78658b74507edafc59f0ff004d51d6be0e45f5 Thanks @jwage
        Hide
        Jonathan H. Wage added a comment -

        This is for sure fixed now with our recent refactoring.

        Show
        Jonathan H. Wage added a comment - This is for sure fixed now with our recent refactoring.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Sebastian Hoitz
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: