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

Embedded relations are not persisted after a flush()

    Details

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

      Description

      Newly added embedded relations do not get persisted when a flush() is executed before they are added to the parent document. Here is a failing test, note the comment "// Adding this flush here makes level1 not to be inserted.":

      public function testFlushEmbedded()

      { $test = new EmbeddedTestLevel0(); $test->name = 'test'; $this->dm->persist($test); $this->dm->flush(); $this->dm->clear(); $test = $this->dm->findOne('Documents\Functional\EmbeddedTestLevel0'); $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); // Adding this flush here makes level1 not to be inserted. $this->dm->flush(); $level1 = new EmbeddedTestLevel1(); $level1->name = 'test level1 #1'; $test->level1[] = $level1; $this->dm->persist($test); $this->dm->flush(); $this->dm->clear(); $test = $this->dm->findOne('Documents\Functional\EmbeddedTestLevel0'); $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); $this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $test->level1[0]); }

        Activity

        Hide
        Vladimir Razuvaev added a comment -

        I also experience this issue. Formatted text from original message for convenience:

        public function testFlushEmbedded() 
        {
        	$test = new EmbeddedTestLevel0(); 
        	$test->name = 'test'; 
        	$this->dm->persist($test); 
        	$this->dm->flush(); 
        	$this->dm->clear(); 
        	$test = $this->dm->findOne('Documents\Functional\EmbeddedTestLevel0');
        	$this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); 
        	// Adding this flush here makes level1 not to be inserted. 
        	$this->dm->flush(); 
        
        	$level1 = new EmbeddedTestLevel1(); 
        	$level1->name = 'test level1 #1'; 
        	$test->level1[] = $level1; 
        	$this->dm->persist($test); 
        	$this->dm->flush(); 
        	$this->dm->clear(); 
        	$test = $this->dm->findOne('Documents\Functional\EmbeddedTestLevel0'); 
        	$this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); 
        	$this->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $test->level1[0]); 
        }
        
        Show
        Vladimir Razuvaev added a comment - I also experience this issue. Formatted text from original message for convenience: public function testFlushEmbedded() { $test = new EmbeddedTestLevel0(); $test->name = 'test'; $ this ->dm->persist($test); $ this ->dm->flush(); $ this ->dm->clear(); $test = $ this ->dm->findOne('Documents\Functional\EmbeddedTestLevel0'); $ this ->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); // Adding this flush here makes level1 not to be inserted. $ this ->dm->flush(); $level1 = new EmbeddedTestLevel1(); $level1->name = 'test level1 #1'; $test->level1[] = $level1; $ this ->dm->persist($test); $ this ->dm->flush(); $ this ->dm->clear(); $test = $ this ->dm->findOne('Documents\Functional\EmbeddedTestLevel0'); $ this ->assertInstanceOf('Documents\Functional\EmbeddedTestLevel0', $test); $ this ->assertInstanceOf('Documents\Functional\EmbeddedTestLevel1', $test->level1[0]); }
        Hide
        Jonathan H. Wage added a comment -

        Do you all have the cascade operating enabled in your mapping?

        Show
        Jonathan H. Wage added a comment - Do you all have the cascade operating enabled in your mapping?
        Show
        Jonathan H. Wage added a comment - Fixed in http://github.com/doctrine/mongodb-odm/commit/20033a35a9cbf345636defdaaaa57204bae8fbab

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Pablo Godel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: