getParentAssociation() public method

list($mapping, $parent, $propertyPath) = $this->getParentAssociation($embeddedDocument);
public getParentAssociation ( object $document ) : array
$document object
return array $association
 /**
  * @param object $embeddeDoc
  * @return bool
  */
 private function isPartOfAtomicUpdate($embeddeDoc)
 {
     $isInDirtyCollection = false;
     while (null !== ($parentAssoc = $this->uow->getParentAssociation($embeddeDoc))) {
         list($mapping, $embeddeDoc, ) = $parentAssoc;
         if ($mapping['association'] === ClassMetadata::EMBED_MANY) {
             $classMetadata = $this->dm->getClassMetadata(get_class($embeddeDoc));
             $parentColl = $classMetadata->getFieldValue($embeddeDoc, $mapping['fieldName']);
             $isInDirtyCollection |= $parentColl->isDirty();
         }
     }
     return isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_MANY && ($mapping['strategy'] === 'atomicSet' || $mapping['strategy'] === 'atomicSetArray') && $isInDirtyCollection;
 }
示例#2
0
 private function getAtomicCollectionUpdateQuery($document)
 {
     $update = array();
     $atomicCollUpdates = array();
     $atomicCollDeletes = array();
     $collPersister = $this->uow->getCollectionPersister();
     /* Collect all atomic collections (top-level and nested) to be included
      * in the update.
      */
     foreach ($this->uow->getScheduledCollections($document) as $coll) {
         /* If this is a top-level, atomic collection, its scheduled update
          * or deletion must be included in the document's update query.
          */
         if ($coll->getOwner() === $document) {
             $mapping = $coll->getMapping();
             if ($mapping['strategy'] !== "atomicSet" && $mapping['strategy'] !== "atomicSetArray") {
                 continue;
             }
             if ($this->uow->isCollectionScheduledForUpdate($coll)) {
                 $atomicCollUpdates[spl_object_hash($coll)] = $coll;
             } elseif ($this->uow->isCollectionScheduledForDeletion($coll)) {
                 $atomicCollDeletes[spl_object_hash($coll)] = $coll;
             }
             continue;
         }
         /* Otherwise, the collection is nested. Check if its top-most parent
          * is an atomic collection and include it for updating if so. This
          * is necessary because the atomic parent may not have directly
          * changed.
          */
         $parent = $coll->getOwner();
         while (null !== ($parentAssoc = $this->uow->getParentAssociation($parent))) {
             list($mapping, $parent, ) = $parentAssoc;
         }
         if (!isset($mapping['association']) || $mapping['association'] !== ClassMetadata::EMBED_MANY || $mapping['strategy'] !== 'atomicSet' && $mapping['strategy'] !== 'atomicSetArray') {
             continue;
         }
         $classMetadata = $this->dm->getClassMetadata(get_class($document));
         $parentColl = $classMetadata->getFieldValue($document, $mapping['fieldName']);
         /* It's possible that the atomic parent was independently scheduled
          * for deletion. In that case, updating nested data is unnecessary.
          */
         if (!$this->uow->isCollectionScheduledForDeletion($parentColl)) {
             $atomicCollUpdates[spl_object_hash($parentColl)] = $parentColl;
         }
     }
     foreach ($atomicCollUpdates as $coll) {
         $update = array_merge_recursive($update, $collPersister->prepareSetQuery($coll));
         /* Note: If the collection is only be handled because it's an atomic
          * parent of a scheduled child, the following calls are NOPs.
          */
         $this->uow->unscheduleCollectionUpdate($coll);
     }
     foreach ($atomicCollDeletes as $coll) {
         $update = array_merge_recursive($update, $collPersister->prepareDeleteQuery($coll));
         /* Note: We don't need to call unscheduleCollectionUpdate(), because
          * the collection should never have been added to $atomicCollDeletes
          * if it was independently scheduled for update.
          */
         $this->uow->unscheduleCollectionDeletion($coll);
     }
     return $update;
 }