Skip to content

Commit 1e46790

Browse files
author
Ville Mattila
committed
Implemented a test to confirm behavior of issue #301
1 parent d948bc2 commit 1e46790

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Doctrine\ODM\MongoDB\Tests;
4+
5+
use Doctrine\Common\Collections\ArrayCollection;
6+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
7+
8+
class GH301Test extends BaseTest
9+
{
10+
public function testPersistIsCascadedInSingleDocumentFlush()
11+
{
12+
$ref = new GH301Document();
13+
$ref->name = 'referenced';
14+
15+
$doc = new GH301Document();
16+
$doc->name = 'parent';
17+
$doc->refOnePersist = $ref;
18+
19+
$this->dm->persist($doc);
20+
$this->dm->flush($doc);
21+
$this->dm->clear();
22+
23+
$docId = $doc->id; unset($doc);
24+
$refId = $ref->id; unset($ref);
25+
26+
$doc = $this->dm->find(__NAMESPACE__ . '\GH301Document', $docId);
27+
$this->assertNotNull($doc);
28+
$this->assertEquals($refId, $doc->refOnePersist->id);
29+
}
30+
}
31+
32+
/** @ODM\Document */
33+
class GH301Document
34+
{
35+
/** @ODM\Id */
36+
public $id;
37+
38+
/** @ODM\String */
39+
public $name;
40+
41+
/**
42+
* @ODM\ReferenceOne(targetDocument="GH301Document", cascade="persist")
43+
*/
44+
public $refOnePersist;
45+
}

0 commit comments

Comments
 (0)