Skip to content

Commit 4ac50ee

Browse files
authored
Merge pull request #1461 from malarzm/gh1456-2
Do not refresh documents when loading sorted collection
2 parents df0771f + ac68123 commit 4ac50ee

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,11 @@ private function loadReferenceManyCollectionOwningSide(PersistentCollection $col
713713
$documents = $cursor->toArray(false);
714714
foreach ($documents as $documentData) {
715715
$document = $this->uow->getById($documentData['_id'], $class);
716-
$data = $this->hydratorFactory->hydrate($document, $documentData);
717-
$this->uow->setOriginalDocumentData($document, $data);
718-
$document->__isInitialized__ = true;
716+
if ($document instanceof Proxy && ! $document->__isInitialized()) {
717+
$data = $this->hydratorFactory->hydrate($document, $documentData);
718+
$this->uow->setOriginalDocumentData($document, $data);
719+
$document->__isInitialized__ = true;
720+
}
719721
if ($sorted) {
720722
$collection->add($document);
721723
}

tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,11 @@ public function testSortReferenceManyOwningSide()
334334
$this->assertEquals('Group 1', $groups[0]->getName());
335335
$this->assertEquals('Group 2', $groups[1]->getName());
336336

337+
$groups[1]->setName('Group 2a');
338+
337339
$groups = $user->getSortedDescGroups();
338340
$this->assertEquals(2, $groups->count());
339-
$this->assertEquals('Group 2', $groups[0]->getName());
341+
$this->assertEquals('Group 2a', $groups[0]->getName());
340342
$this->assertEquals('Group 1', $groups[1]->getName());
341343
}
342344

0 commit comments

Comments
 (0)