Permalink
Browse files

[MODM-41] Fixing PersistentReferenceCollection initialization.

  • Loading branch information...
1 parent ad8a782 commit cbe22dfd50225250ab468ea2f5e243736b2f35fd @jwage jwage committed Aug 7, 2010
@@ -23,6 +23,7 @@
Doctrine\ODM\MongoDB\Mapping\ClassMetadata,
Doctrine\ODM\MongoDB\Proxy\Proxy,
Doctrine\ODM\MongoDB\DocumentManager,
+ Doctrine\ODM\MongoDB\Query,
Closure;
/**
@@ -68,15 +69,15 @@ protected function _initialize()
continue;
}
$class = $this->_dm->getClassMetadata(get_class($document));
- $ids[$class->name][] = $class->getIdentifierObject($document);
+ $groupedIds[$class->name][] = $class->getIdentifierObject($document);
}
foreach ($groupedIds as $className => $ids) {
$collection = $this->_dm->getDocumentCollection($className);
$data = $collection->find(array('_id' => array($this->_cmd . 'in' => $ids)));
$hints = array(Query::HINT_REFRESH => Query::HINT_REFRESH);
foreach ($data as $id => $documentData) {
- $document = $this->_dm->getUnitOfWork()->getOrCreateDocument($this->_typeClass->name, $documentData, $hints);
+ $document = $this->_dm->getUnitOfWork()->getOrCreateDocument($className, $documentData, $hints);
if ($document instanceof Proxy) {
$document->__isInitialized__ = true;
unset($document->__dm);
@@ -122,6 +122,7 @@ public function testManyReference()
$this->assertTrue($groups instanceof PersistentReferenceCollection);
$this->assertTrue($groups[0]->getId() !== '');
$this->assertTrue($groups[1]->getId() !== '');
+ $this->dm->clear();
$user2 = $this->dm->createQuery('Documents\User')
->field('id')
@@ -130,6 +131,10 @@ public function testManyReference()
$groups = $user2->getGroups();
+ $groupsArray = $groups->toArray();
+ $this->assertTrue($groupsArray[0]->__isInitialized__);
+ $this->assertTrue($groupsArray[1]->__isInitialized__);
+
$this->assertTrue($groups instanceof PersistentReferenceCollection);
$this->assertTrue($groups[0] instanceof Group);
$this->assertTrue($groups[1] instanceof Group);

0 comments on commit cbe22df

Please sign in to comment.