/** * Inserts new rows for a PersistentCollection instance. * * @param PersistentCollection $coll * @param array $options */ private function insertRows(PersistentCollection $coll, array $options) { $mapping = $coll->getMapping(); list($propertyPath, $parent) = $this->getPathAndParent($coll); if ($mapping['strategy'] === 'set') { $setData = array(); foreach ($coll as $document) { if (isset($mapping['reference'])) { $setData[] = $this->pb->prepareReferencedDocValue($mapping, $document); } else { $setData[] = $this->pb->prepareEmbeddedDocValue($mapping, $document); } } $query = array($this->cmd.'set' => array($propertyPath => $setData)); $this->executeQuery($parent, $query, $options); } else { $strategy = isset($mapping['strategy']) ? $mapping['strategy'] : 'pushAll'; $insertDiff = $coll->getInsertDiff(); if ($insertDiff) { $query = array($this->cmd.$strategy => array()); foreach ($insertDiff as $key => $document) { if (isset($mapping['reference'])) { $query[$this->cmd.$strategy][$propertyPath][] = $this->pb->prepareReferencedDocValue($mapping, $document); } else { $query[$this->cmd.$strategy][$propertyPath][] = $this->pb->prepareEmbeddedDocValue($mapping, $document); } } $this->executeQuery($parent, $query, $options); } } }