Skip to content

Commit

Permalink
Added test case for MODM76.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianhoitz committed Sep 20, 2010
1 parent 5c9f6e6 commit 9ec3406
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/Doctrine/ODM/MongoDB/Persisters/BasicDocumentPersister.php
Expand Up @@ -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);
}
Expand Down
67 changes: 67 additions & 0 deletions 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;
}

0 comments on commit 9ec3406

Please sign in to comment.