public function getReferencedDocumentList($name)
{
$referenceList = $this->get($name);
if (null === $referenceList) {
return null;
}
if (!isset($referenceList[0])) {
throw new Exception('List of references not found');
}
// build list of referenced collections and ids
$documentIdList = array();
foreach ($referenceList as $reference) {
if (empty($reference['$ref']) || empty($reference['$id'])) {
throw new Exception(sprintf('Iinvalid reference in list for document %s in field %s', $this->getId(), $name));
}
$documentIdList[$reference['$ref']][] = $reference['$id'];
}
// get list
$documentList = array();
$database = $this->collection->getDatabase();
foreach ($documentIdList as $collectionName => $documentIdList) {
$documentList += $database->getCollection($collectionName)->find()->byIdList($documentIdList)->findAll();
}
return $documentList;
}