Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test case for MODM76.

  • Loading branch information...
commit 9ec340697b184284f420e077457127f3147566e0 1 parent 5c9f6e6
@sebastianhoitz authored
View
16 lib/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php
@@ -561,15 +561,13 @@ private function prepareValue(array $mapping, $value)
private function prepareReferencedDocValue(array $referenceMapping, $document)
{
$id = null;
-
- if (is_array($document)) {
- $className = $referenceMapping['targetDocument'];
- } else {
- $className = get_class($document);
- $id = $this->uow->getDocumentIdentifier($document);
- }
-
- $class = $this->dm->getClassMetadata($className);
+ if (is_array($document)) {
+ $className = $referenceMapping['targetDocument'];
+ } else {
+ $className = get_class($document);
+ $id = $this->uow->getDocumentIdentifier($document);
+ }
+ $class = $this->dm->getClassMetadata($className);
if (null !== $id) {
$id = $class->getDatabaseIdentifierValue($id);
}
View
67 tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM76Test.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
+
+require_once __DIR__ . '/../../../../../../TestInit.php';
+
+use Doctrine\Common\Collections\ArrayCollection;
+
+class MODM76Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest {
+
+ public function testTest() {
+ $c1 = new C;
+ $c2 = new C;
+ $b = new B(array($c1, $c2));
+ $a = new A(array($b), array($c1));
+ $this->dm->persist($a);
+ $this->dm->flush();
+
+ $this->assertTrue($a->getId() != null);
+ }
+}
+
+/** @Document(db="tests", collection="tests") */
+class A {
+ /** @Id */
+ protected $id;
+ /** @EmbedMany(targetDocument="b") */
+ protected $b = array();
+ /** @ReferenceMany(targetDocument="c") */
+ protected $c = array();
+
+ public function __construct($b, $c) {
+ $this->b = new ArrayCollection($b);
+ $this->c = new ArrayCollection($c);
+ }
+
+ public function getB() {
+ return $this->b;
+ }
+
+ public function getC() {
+ return $this->c;
+ }
+
+ public function getId() {
+ return $this->id;
+ }
+}
+
+/** @EmbeddedDocument */
+class B {
+ /** @ReferenceOne(targetDocument="c") */
+ protected $c;
+
+ public function __construct($c) {
+ $this->c = $c;
+ }
+
+ public function getC() {
+ return $this->c;
+ }
+}
+/** @Document(db="tests", collection="tests2") */
+class C {
+ /** @Id */
+ protected $id;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.