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

Issue with nested embdedded documents after adding an EmbeddedDocument to Document

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0.0BETA3
    • Fix Version/s: None
    • Component/s: UnitOfWork
    • Labels:
      None
    • Environment:
      PHP 5.3.3, Mac OS X 10.6.6, MongoDB 1.8.0

      Description

      I'm using the latest version of Doctrine ODM (fresh from Git).

      I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

      Step-by-step:

      1. Make a new Post (Post1), 2 PostVersions (PostVersion1 and 2) and a Category
      2. Add Post1 to Category
      3. Persist Category, Flush, Clear
      4. Retrieve Category
      5. Make a new Post (Post2) and 2 PostVersions(PostVersion3 and 4)
      6. Add Post2 to Category
      7. Flush

      If you're following properly, at this stage in the database there should be:
      1 Category,
      2 Posts
      4 PostVersions ... 2 PostVersions in each Post

      However, what actually happens is:
      1 Category,
      2 Posts
      4 PostVersions ... 4 PostVersions in Post1, 0 PostVersions in Post2

      On StackOverflow: http://bit.ly/ekFbe2
      Testcase Gist: https://gist.github.com/920914

      A work around is to make Post2 and add it to Category, flush, then make new PostVersions and flush again.

      I did some debugging but I don't know enough about the internals to fix the issue.

      1. doctrine-odm-patch-1.0.0beta3.diff
        4 kB
        Kelvin Wood
      2. MODM140Test.php
        2 kB
        Andrew Cobby

        Activity

        Andrew Cobby created issue -
        Hide
        Andrew Cobby added a comment -

        Failing test

        Show
        Andrew Cobby added a comment - Failing test
        Andrew Cobby made changes -
        Field Original Value New Value
        Attachment MODM140Test.php [ 10972 ]
        Andrew Cobby made changes -
        Description I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        PostVersion is automatically handled by Post. When I make a new post, it actually makes a new PostVersion under the hood as well. I think this is irrelevant as this is working correctly.

        My issue is that Doctrine get confused with PostVersions, if I retrieve an existing Category and add a new Post to it, the new Post's PostVersions get add to the first Post in the Category's $posts collection.


        Step-by-step:

         1. Make a new Post (Post1) and Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2)
         6. Add Post2 to Category
         7. Flush

        At this stage in the database, there should be one Category, two Posts and each Post has one PostVersion. However, what actually happens is there is one Category, two Posts, the first Post has two PostVersions and the second Post has zero PostVersions.

        The Documents themselves during the request are correct, it's just want is persisted to the database that is wrong. What am I missing?

        On StackOverflow: http://bit.ly/ekFbe2
        I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        PostVersion is automatically handled by Post. When I make a new post, it actually makes a new PostVersion under the hood as well. I think this is irrelevant as this is working correctly.

        My issue is that Doctrine get confused with PostVersions, if I retrieve an existing Category and add a new Post to it, the new Post's PostVersions get add to the first Post in the Category's $posts collection.


        Step-by-step:

         1. Make a new Post (Post1) and Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2)
         6. Add Post2 to Category
         7. Flush

        At this stage in the database, there should be one Category, two Posts and each Post has one PostVersion. However, what actually happens is there is one Category, two Posts, the first Post has two PostVersions and the second Post has zero PostVersions.

        On StackOverflow: http://bit.ly/ekFbe2

        I did some debugging but I don't know enough about the internals to fix the issue.
        Andrew Cobby made changes -
        Description I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        PostVersion is automatically handled by Post. When I make a new post, it actually makes a new PostVersion under the hood as well. I think this is irrelevant as this is working correctly.

        My issue is that Doctrine get confused with PostVersions, if I retrieve an existing Category and add a new Post to it, the new Post's PostVersions get add to the first Post in the Category's $posts collection.


        Step-by-step:

         1. Make a new Post (Post1) and Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2)
         6. Add Post2 to Category
         7. Flush

        At this stage in the database, there should be one Category, two Posts and each Post has one PostVersion. However, what actually happens is there is one Category, two Posts, the first Post has two PostVersions and the second Post has zero PostVersions.

        On StackOverflow: http://bit.ly/ekFbe2

        I did some debugging but I don't know enough about the internals to fix the issue.
        I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        PostVersion is automatically handled by Post. When I make a new post, it actually makes a new PostVersion under the hood as well. This is kind of irrelevant as this is working correctly, but just remember making a new Post also makes a PostVersion.

        Step-by-step:

         1. Make a new Post (Post1) and Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2)
         6. Add Post2 to Category
         7. Flush

        At this stage in the database, there should be one Category, two Posts and each Post has one PostVersion. However, what actually happens is there is one Category, two Posts, the first Post has two PostVersions and the second Post has zero PostVersions.

        On StackOverflow: http://bit.ly/ekFbe2

        I did some debugging but I don't know enough about the internals to fix the issue.
        Hide
        Andrew Cobby added a comment - - edited

        Added a test using the EmbdeddedTestLevelX Documents, please refer to Gist: https://gist.github.com/920914

        For some reason, they work? I'm thinking maybe this isn't a bug... very confused at the moment.

        Show
        Andrew Cobby added a comment - - edited Added a test using the EmbdeddedTestLevelX Documents, please refer to Gist: https://gist.github.com/920914 For some reason, they work? I'm thinking maybe this isn't a bug... very confused at the moment.
        Andrew Cobby made changes -
        Description I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        PostVersion is automatically handled by Post. When I make a new post, it actually makes a new PostVersion under the hood as well. This is kind of irrelevant as this is working correctly, but just remember making a new Post also makes a PostVersion.

        Step-by-step:

         1. Make a new Post (Post1) and Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2)
         6. Add Post2 to Category
         7. Flush

        At this stage in the database, there should be one Category, two Posts and each Post has one PostVersion. However, what actually happens is there is one Category, two Posts, the first Post has two PostVersions and the second Post has zero PostVersions.

        On StackOverflow: http://bit.ly/ekFbe2

        I did some debugging but I don't know enough about the internals to fix the issue.
        I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        Step-by-step:

         1. Make a new Post (Post1), 2 PostVersions (PostVersion1 and 2) and a Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2) and 2 PostVersions(PostVersion3 and 4)
         6. Add Post2 to Category
         7. Flush

        If you're following properly, at this stage in the database there should be:
        1 Category,
        2 Posts
        4 PostVersions ... *2* PostVersions in each Post

        However, what actually happens is:
        1 Category,
        2 Posts
        4 PostVersions ... *4* PostVersions in Post1, *0* PostVersions in Post2

        On StackOverflow: http://bit.ly/ekFbe2

        I did some debugging but I don't know enough about the internals to fix the issue.
        Andrew Cobby made changes -
        Description I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        Step-by-step:

         1. Make a new Post (Post1), 2 PostVersions (PostVersion1 and 2) and a Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2) and 2 PostVersions(PostVersion3 and 4)
         6. Add Post2 to Category
         7. Flush

        If you're following properly, at this stage in the database there should be:
        1 Category,
        2 Posts
        4 PostVersions ... *2* PostVersions in each Post

        However, what actually happens is:
        1 Category,
        2 Posts
        4 PostVersions ... *4* PostVersions in Post1, *0* PostVersions in Post2

        On StackOverflow: http://bit.ly/ekFbe2

        I did some debugging but I don't know enough about the internals to fix the issue.
        I'm using the latest version of Doctrine ODM (fresh from Git).

        I have three levels of Documents (Two embedded); Category -> EmbedsMany: Post -> EmbedsMany PostVersion.

        Step-by-step:

         1. Make a new Post (Post1), 2 PostVersions (PostVersion1 and 2) and a Category
         2. Add Post1 to Category
         3. Persist Category, Flush, Clear
         4. Retrieve Category
         5. Make a new Post (Post2) and 2 PostVersions(PostVersion3 and 4)
         6. Add Post2 to Category
         7. Flush

        If you're following properly, at this stage in the database there should be:
        1 Category,
        2 Posts
        4 PostVersions ... *2* PostVersions in each Post

        However, what actually happens is:
        1 Category,
        2 Posts
        4 PostVersions ... *4* PostVersions in Post1, *0* PostVersions in Post2

        On StackOverflow: http://bit.ly/ekFbe2
        Testcase Gist: https://gist.github.com/920914

        A work around is to make Post2 and add it to Category, flush, then make new PostVersions and flush again.

        I did some debugging but I don't know enough about the internals to fix the issue.
        Hide
        Andras Revai added a comment -

        I've got the same problem.

        Show
        Andras Revai added a comment - I've got the same problem.
        Hide
        Kelvin Wood added a comment -

        I had a similar problem, and resolved it with the attached patch (based on the 1.0.0beta3 release).

        This patch causes the ODM to stop scanning for changes further down the heirachy once it finds a new object, and then ensures that the Persistence Builder will include all contents of the new item.

        Show
        Kelvin Wood added a comment - I had a similar problem, and resolved it with the attached patch (based on the 1.0.0beta3 release). This patch causes the ODM to stop scanning for changes further down the heirachy once it finds a new object, and then ensures that the Persistence Builder will include all contents of the new item.
        Kelvin Wood made changes -
        Attachment doctrine-odm-patch-1.0.0beta3.diff [ 11044 ]
        Hide
        Richard Shank added a comment -

        Kevin, do you want to put a PR in on github for this?

        Show
        Richard Shank added a comment - Kevin, do you want to put a PR in on github for this?

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=MODM-140, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Andrew Cobby
          • Votes:
            5 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated: