Doctrine\ODM\MongoDB\PersistentCollection::getInsertDiff PHP Method

getInsertDiff() public method

INTERNAL: getInsertDiff
public getInsertDiff ( ) : array
return array
    public function getInsertDiff()
    {
        return array_udiff_assoc($this->coll->toArray(), $this->snapshot,
                function($a, $b) {return $a === $b ? 0 : 1;});
    }

Usage Example

 /**
  * Inserts new elements for a PersistentCollection instance.
  *
  * This method is intended to be used with the "pushAll" and "addToSet"
  * strategies.
  *
  * @param PersistentCollection $coll
  * @param array $options
  */
 private function insertElements(PersistentCollection $coll, array $options)
 {
     $insertDiff = $coll->getInsertDiff();
     if (empty($insertDiff)) {
         return;
     }
     $mapping = $coll->getMapping();
     list($propertyPath, $parent) = $this->getPathAndParent($coll);
     $pb = $this->pb;
     $callback = isset($mapping['embedded']) ? function ($v) use($pb, $mapping) {
         return $pb->prepareEmbeddedDocumentValue($mapping, $v);
     } : function ($v) use($pb, $mapping) {
         return $pb->prepareReferencedDocumentValue($mapping, $v);
     };
     $value = array_values(array_map($callback, $insertDiff));
     if ($mapping['strategy'] === 'addToSet') {
         $value = array('$each' => $value);
     }
     $query = array('$' . $mapping['strategy'] => array($propertyPath => $value));
     $this->executeQuery($parent, $query, $options);
 }
All Usage Examples Of Doctrine\ODM\MongoDB\PersistentCollection::getInsertDiff