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

            People

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

              Dates

              • Created:
                Updated:
                Resolved: