private function loadReferenceManyCollectionOwningSide(PersistentCollection $collection)
{
$mapping = $collection->getMapping();
$groupedIds = array();
$sorted = isset($mapping['sort']) && $mapping['sort'];
foreach ($collection->getMongoData() as $key => $reference) {
if (isset($mapping['simple']) && $mapping['simple']) {
$className = $mapping['targetDocument'];
$mongoId = $reference;
} else {
$className = $this->uow->getClassNameForAssociation($mapping, $reference);
$mongoId = $reference['$id'];
}
$id = $this->dm->getClassMetadata($className)->getPHPIdentifierValue($mongoId);
$reference = $this->dm->getReference($className, $id);
/* If the reference has custom sort, remember IDs to execute the query later.
* Otherwise add the references right now in the order they are embedded.
*/
if ($sorted) {
$groupedIds[$className][] = $mongoId;
} else {
if ($mapping['strategy'] === 'set') {
$collection->set($key, $reference);
} else {
$collection->add($reference);
}
}
}
if ($sorted && count($groupedIds)) {
$this->loadActualDataForSortedReferenceManyCollectionByIds($collection, $groupedIds);
}
}