Пример #1
0
 private function loadEmbedManyCollection(PersistentCollection $collection)
 {
     $embeddedDocuments = $collection->getMongoData();
     $mapping = $collection->getMapping();
     $owner = $collection->getOwner();
     if ($embeddedDocuments) {
         foreach ($embeddedDocuments as $key => $embeddedDocument) {
             $className = $this->uow->getClassNameForAssociation($mapping, $embeddedDocument);
             $embeddedMetadata = $this->dm->getClassMetadata($className);
             $embeddedDocumentObject = $embeddedMetadata->newInstance();
             $this->uow->setParentAssociation($embeddedDocumentObject, $mapping, $owner, $mapping['name'] . '.' . $key);
             $data = $this->hydratorFactory->hydrate($embeddedDocumentObject, $embeddedDocument);
             $id = $embeddedMetadata->identifier && isset($data[$embeddedMetadata->identifier]) ? $data[$embeddedMetadata->identifier] : null;
             $this->uow->registerManaged($embeddedDocumentObject, $id, $data);
             if (CollectionHelper::isHash($mapping['strategy'])) {
                 $collection->set($key, $embeddedDocumentObject);
             } else {
                 $collection->add($embeddedDocumentObject);
             }
         }
     }
 }