Skip to content

Commit

Permalink
[MODM-41] Fixing PersistentReferenceCollection initialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Aug 7, 2010
1 parent ad8a782 commit cbe22df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Expand Up @@ -23,6 +23,7 @@
Doctrine\ODM\MongoDB\Mapping\ClassMetadata,
Doctrine\ODM\MongoDB\Proxy\Proxy,
Doctrine\ODM\MongoDB\DocumentManager,
Doctrine\ODM\MongoDB\Query,
Closure;

/**
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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')
Expand All @@ -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);
Expand Down

0 comments on commit cbe22df

Please sign in to comment.