setParentAssociation() public method

Sets the parent association for a given embedded document.
public setParentAssociation ( object $document, array $mapping, object $parent, string $propertyPath )
$document object
$mapping array
$parent object
$propertyPath string
コード例 #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->dm->getClassNameFromDiscriminatorValue($mapping, $embeddedDocument);
             $embeddedMetadata = $this->dm->getClassMetadata($className);
             $embeddedDocumentObject = $embeddedMetadata->newInstance();
             $data = $this->hydratorFactory->hydrate($embeddedDocumentObject, $embeddedDocument);
             $this->uow->registerManaged($embeddedDocumentObject, null, $data);
             $this->uow->setParentAssociation($embeddedDocumentObject, $mapping, $owner, $mapping['name'] . '.' . $key);
             $collection->add($embeddedDocumentObject);
         }
     }
 }
コード例 #2
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);
             }
         }
     }
 }