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

Bug when persisting referenced collection

    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

      After adding new entry to referenced collection of existing document, ODM generates invalid update query.

      Here is a test case:

      /** @Document(db="tests", collection="tests") */
      class a
      {
          /** @Id */
          protected $id;
      
          /** @ReferenceMany(targetDocument="b", cascade="all") */
          protected $b;
      
          function __construct($b) {$this->b = new ArrayCollection($b);}
      
          function getB() {return $this->b;}
      }
      
      /** @Document(db="tests", collection="tests2") */
      class b
      {
          /** @Id */
          protected $id;
      
          /** @String */
          protected $tmp;
      
          function __construct($v) {$this->tmp = $v;}
      }
      
      $a = new a(array(new b('first')));
      $dm->persist($a);
      $dm->flush(); // flush causes notices
      $dm->refresh($a);
      
      $a->getB()->add(new b('second'));
      $dm->persist($a);
      $dm->flush();
      $dm->refresh($a);
      
      print_r($a->getB()->toArray());
      

      Expecting following output:

      Array
      (
          [0] => b Object
              (
                  [id:protected] => 4c7c9eea0f9d502005000000
                  [tmp:protected] => first
              )
      
          [1] => b Object
              (
                  [id:protected] => 4c7c9eea0f9d502005020000
                  [tmp:protected] => second
              )
      
      )
      

      But getting:

      Array
      (
          [0] => b Object
              (
                  [id:protected] => 4c7c9eea0f9d502005000000
                  [tmp:protected] => first
              )
      
          [1] => b Object
              (
                  [id:protected] => 4c7c9eea0f9d502005000000
                  [tmp:protected] => first
              )
      
          [2] => b Object
              (
                  [id:protected] => 4c7c9eea0f9d502005020000
                  [tmp:protected] => second
              )
      
      )
      

        Issue Links

          Activity

          Hide
          Thomas Adam added a comment -

          Ok. I added a PHPUnit test case in MODM-70.
          I hope this helps.

          Show
          Thomas Adam added a comment - Ok. I added a PHPUnit test case in MODM-70 . I hope this helps.
          Hide
          Bulat Shakirzyanov added a comment -

          Thomas, it would help me very much if you created a phpunit test case that fails.

          Show
          Bulat Shakirzyanov added a comment - Thomas, it would help me very much if you created a phpunit test case that fails.
          Hide
          Bulat Shakirzyanov added a comment -

          Thomas, the MODM-70 ticket is still open
          Jon, can you please remove related to MODM-70, so that we don't confuse Thomas.
          I am working on that ticket.

          Show
          Bulat Shakirzyanov added a comment - Thomas, the MODM-70 ticket is still open Jon, can you please remove related to MODM-70 , so that we don't confuse Thomas. I am working on that ticket.
          Hide
          Thomas Adam added a comment -

          So I recorded all the updates, but my test document still does not work. The test for
          this ticket is working, but not the test of my comment. Did they not make the mistake that he is a
          push with initial values and sets makes name and gender again? Please give me an answer.
          With this error is useless for me odm, because I can save anything, because everything in there twice
          stands. There are also variables Increments etc.

          Show
          Thomas Adam added a comment - So I recorded all the updates, but my test document still does not work. The test for this ticket is working, but not the test of my comment. Did they not make the mistake that he is a push with initial values and sets makes name and gender again? Please give me an answer. With this error is useless for me odm, because I can save anything, because everything in there twice stands. There are also variables Increments etc.
          Hide
          Bulat Shakirzyanov added a comment -

          resolved

          Show
          Bulat Shakirzyanov added a comment - resolved

            People

            • Assignee:
              Bulat Shakirzyanov
              Reporter:
              Vladimir Razuvaev
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: