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

Changes of nested embedded collection are not persisted

    Details

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

      Description

      When there is a nested EmbedMany collection, changes of this collection are not persisted when saving root document.

      Maybe simpler to explain with a test case:

      /**
       * @MappedSuperClass
       */
      class container
      {
          /** @String */
          protected $tmp = 'ensureSaved';
      
          /** @EmbedMany(targetDocument="emb", cascade="all", strategy="set") */
          protected $items = array();
      
          function __construct($items = null) {if($items) $this->items = $items;}
          function getItems() {return $this->items;}
          function getItem($index) {return $this->items[$index];}
          function removeItem($i) {unset($this->items[$i]);}
      }
      
      /** @EmbeddedDocument */
      class emb extends container
      {}
      
      /** @Document(db="tests", collection="tests") */
      class doc extends container
      {
          /** @Id */
          protected $id;
      }
      
      $emb = new emb(array(new emb(), new emb()));
      $doc = new doc(array($emb));
      
      $dm->persist($doc);
      $dm->flush();
      $dm->refresh($doc);
      
      // change nested embedded collection:
      $doc->getItem(0)->removeItem(1);
      $before = count($doc->getItem(0)->getItems());
      
      $dm->persist($doc);
      $dm->flush();
      $dm->refresh($doc);
      
      $after = count($doc->getItem(0)->getItems());
      var_dump($before); // outputs 1
      var_dump($after);  // outputs 2, but expecting 1
      

        Activity

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Vladimir Razuvaev
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: