Uploaded image for project: 'Doctrine MongoDB ODM'
  1. Doctrine MongoDB ODM
  2. MODM-83

UnitOfWork incorrectly updates all documents with embedded documents on flush

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: UnitOfWork
    • Labels:
      None
    • Environment:
      OS X 10.6.4, PHP 5.3.2, Mongo 1.6.3 (can reproduce on Ubuntu 8.04.4 LTS, CentOS, Win 7, etc)

      Description

      UnitOfWork incorrectly contains every managed document with embedded documents. All embedded documents are marked as updated. The whole mess will be updated on the next flush, regardless of whether said documents have actually changed.

      Branch here: http://github.com/opensky/mongodb-odm/tree/MODM-83

      Test case here: http://github.com/opensky/mongodb-odm/commit/af4373b58dd5da0bea5a0f8c4da30dde5ed1f266

      Here's what the document changeset looks like in preUpdate and postUpdate:

      preUpdate "Doctrine\ODM\MongoDB\Tests\Functional\Ticket\MODM83OtherDocument"

      array(1) {
        ["name"]=>
        array(2) {
          [0]=>
          string(8) "Neighbor"
          [1]=>
          string(3) "Bob"
        }
      }
      

      postUpdate "Doctrine\ODM\MongoDB\Tests\Functional\Ticket\MODM83OtherDocument"

      array(1) {
        ["name"]=>
        array(2) {
          [0]=>
          string(8) "Neighbor"
          [1]=>
          string(3) "Bob"
        }
      }
      

      preUpdate "Doctrine\ODM\MongoDB\Tests\Functional\Ticket\MODM83TestDocument"

      array(1) {
        ["embedded"]=>
        array(2) {
          [0]=>
          array(1) {
            ["name"]=>
            string(5) "Child"
          }
          [1]=>
          array(2) {
            ["name"]=>
            string(5) "Child"
            ["originalObject"]=>
            object(Doctrine\ODM\MongoDB\Tests\Functional\Ticket\MODM83TestEmbeddedDocument)#86 (1) {
              ["name"]=>
              string(5) "Child"
            }
          }
        }
      }
      

      postUpdate "Doctrine\ODM\MongoDB\Tests\Functional\Ticket\MODM83TestDocument"

      array(1) {
        ["embedded"]=>
        array(2) {
          [0]=>
          array(1) {
            ["name"]=>
            string(5) "Child"
          }
          [1]=>
          array(2) {
            ["name"]=>
            string(5) "Child"
            ["originalObject"]=>
            object(Doctrine\ODM\MongoDB\Tests\Functional\Ticket\MODM83TestEmbeddedDocument)#86 (1) {
              ["name"]=>
              string(5) "Child"
            }
          }
        }
      }
      

        Activity

        Show
        jwage Jonathan H. Wage added a comment - Fixed here http://github.com/doctrine/mongodb-odm/commit/8bd3aef4055cfded62687d5ad0e762e3f12a473d
        Hide
        a.koss Alexander Koß added a comment -

        I use this update, now i cant delete childrens with a other embedded document:

        The complete document
         {
           "_id" : ObjectId("4caeea835634c915360a0000"),
           "categories" : {
             "0" : {
               "id" : ObjectId("4cbd55f55634c99177030000"),
               "name" : "neue Kategorie",
               "questions" : {
                 "0" : {
                   "id" : ObjectId("4cbd55f75634c99177040000"),
                   "name" : "neue Frage",
                   "relevance" : 0,
                   "multi" : 0,
                   "answertype" : 0,
                   "other" : 0
                }
              }
            }
          },
           "description" : "pipapo!",
           "name" : "ich bin ein Katalog",
           "version" : 1
        }
        

        Now i add a new answer too the question:

        The question with the new answer
        "questions" : {
                 "0" : {
                   "answers" : {
                     "0" : {
                       "id" : ObjectId("4cbd56b95634c99b5b090000"),
                       "name" : "neue Antwort"
                    }
                  },
                   "answertype" : 0,
                   "id" : ObjectId("4cbd55f75634c99177040000"),
                   "multi" : 0,
                   "name" : "neue Frage",
                   "other" : 0,
                   "relevance" : 0
                } 
        }
        

        When i delete now the new answer i have a empty array and i cant delete the question from the categorie.

        The unkillable question
        "questions" : {
                 "0" : {
                   "answers" : [
                    
                  ],
                   "answertype" : 0,
                   "id" : ObjectId("4cbd55f75634c99177040000"),
                   "multi" : 0,
                   "name" : "neue Frage",
                   "other" : 0,
                   "relevance" : 0
                }
              } 
        

        Its a unkillable entry now.
        Sorry for my bad english, i hope you can fix it, not my english, the bug.

        Show
        a.koss Alexander Koß added a comment - I use this update, now i cant delete childrens with a other embedded document: The complete document { "_id" : ObjectId( "4caeea835634c915360a0000" ), "categories" : { "0" : { "id" : ObjectId( "4cbd55f55634c99177030000" ), "name" : "neue Kategorie" , "questions" : { "0" : { "id" : ObjectId( "4cbd55f75634c99177040000" ), "name" : "neue Frage" , "relevance" : 0, "multi" : 0, "answertype" : 0, "other" : 0 } } } }, "description" : "pipapo!" , "name" : "ich bin ein Katalog" , "version" : 1 } Now i add a new answer too the question: The question with the new answer "questions" : { "0" : { "answers" : { "0" : { "id" : ObjectId( "4cbd56b95634c99b5b090000" ), "name" : "neue Antwort" } }, "answertype" : 0, "id" : ObjectId( "4cbd55f75634c99177040000" ), "multi" : 0, "name" : "neue Frage" , "other" : 0, "relevance" : 0 } } When i delete now the new answer i have a empty array and i cant delete the question from the categorie. The unkillable question "questions" : { "0" : { "answers" : [ ], "answertype" : 0, "id" : ObjectId( "4cbd55f75634c99177040000" ), "multi" : 0, "name" : "neue Frage" , "other" : 0, "relevance" : 0 } } Its a unkillable entry now. Sorry for my bad english, i hope you can fix it, not my english, the bug.
        Hide
        a.koss Alexander Koß added a comment -

        I have create a new issue: MODM-89

        Show
        a.koss Alexander Koß added a comment - I have create a new issue: MODM-89

          People

          • Assignee:
            avalanche123 Bulat Shakirzyanov
            Reporter:
            bobthecow Justin Hileman
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: