/**
* Adds identifiers from a PersistentCollection to $groupedIds.
*
* If the relation contains simple references, the mapping is assumed to
* have a target document class defined. Without that, there is no way to
* infer the class of the referenced documents.
*
* @param PersistentCollection $persistentCollection
* @param array $groupedIds
*/
private function addManyReferences(PersistentCollection $persistentCollection, array &$groupedIds)
{
$mapping = $persistentCollection->getMapping();
if (!empty($mapping['simple'])) {
$className = $mapping['targetDocument'];
$class = $this->dm->getClassMetadata($className);
}
foreach ($persistentCollection->getMongoData() as $reference) {
if (!empty($mapping['simple'])) {
$id = $reference;
} else {
$id = $reference['$id'];
$className = $this->uow->getClassNameForAssociation($mapping, $reference);
$class = $this->dm->getClassMetadata($className);
}
$document = $this->uow->tryGetById($id, $class);
if (!$document || $document instanceof Proxy && !$document->__isInitialized()) {
$id = $class->getPHPIdentifierValue($id);
$groupedIds[$className][serialize($id)] = $id;
}
}
}