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

Embedded document changes are ignored if it was empty before

    Details

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

      Description

      Imaging the object in DB:

      {
        "_id": "4c693f9f0f9d501c0d000000",
        "b": [
        ]
      }
      

      Then following code fails to update property "b":

      /** @Document(db="tests", collection="tests") */
      class a
      {
          /** @Id */
          protected $id;
      
          /** @EmbedOne(targetDocument="b", cascade="all") */
          protected $b;
      
          function getId()  {return $this->id;}
          function getB()   {return $this->b;}
          function setB($b) {$this->b = $b;}
      }
      
      /** @EmbeddedDocument */
      class b
      {
          /** @String */
          protected $val;
          function setVal($val) {$this->val = $val;}
          function getVal() {return $this->val;}
      }
      
      $a = $dm->loadByID('a', '4c693f9f0f9d501c0d000000');
      $a->getB()->setVal('test');
      
      $dm->persist($a);
      $dm->flush();
      $dm->getUnitOfWork()->clear();
      
      $a = $dm->loadByID('a', $a->getId());
      $c = ('test' === $a->getB()->getVal());
      
      var_dump($c); // expecting "true", but outputs false
      

        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: