Example #1
0
 /**
  * Sync data to database. If it's new data, we insert it as new document, otherwise, if the document exists, we just update it.
  *
  * @param Collection $collection
  * @param Model $model
  *
  * @return bool
  */
 public function save(Collection $collection, Model $model)
 {
     $collectionName = $collection->name;
     $data = $this->marshall($model->dump());
     $result = false;
     if (is_null($model->getId())) {
         $id = $this->insert($collectionName, $data);
         if ($id) {
             $model->setId($id);
             $result = true;
         }
     } else {
         $data['id'] = $model->getId();
         $result = $this->update($collectionName, $data);
         if ($result) {
             $result = true;
         }
     }
     return $result;
 }