/**
* 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);
}