Doctrine\ODM\MongoDB\UnitOfWork::setParentAssociation PHP Method

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
    public function setParentAssociation($document, $mapping, $parent, $propertyPath)
    {
        $oid = spl_object_hash($document);
        $this->embeddedDocumentsRegistry[$oid] = $document;
        $this->parentAssociations[$oid] = array($mapping, $parent, $propertyPath);
    }

Usage Example

 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);
         }
     }
 }
All Usage Examples Of Doctrine\ODM\MongoDB\UnitOfWork::setParentAssociation
UnitOfWork