update() public method

Updates this record
public update ( array $attributes = null ) : boolean
$attributes array
return boolean
Exemplo n.º 1
0
 /**
  * Updates the row represented by this active record.
  * All loaded attributes will be saved to the database.
  * Note, validation is not performed in this method. You may call {@link validate} to perform the validation.
  * @param array $attributes list of attributes that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @return boolean whether the update is successful
  * @throws EMongoException if the record is new
  * @since v1.3
  */
 public function update(array $attributes = null, $modify = false)
 {
     Yii::trace('Trace: ' . __CLASS__ . '::' . __FUNCTION__ . '()', 'ext.MongoDb.EMongoGridFS');
     if ($this->getIsNewRecord()) {
         throw new EMongoException(Yii::t('yii', 'The EMongoDocument cannot be updated because it is new.'));
     }
     if (is_file($this->filename) === true) {
         if ($this->deleteByPk($this->_id) !== false) {
             $result = $this->insertWithPk($this->_id, $attributes);
             if ($result === true) {
                 return true;
             } else {
                 return false;
             }
         }
     } else {
         return parent::update($attributes, true);
     }
 }
Exemplo n.º 2
0
 /**
  * Updates the row represented by this active record.
  * All loaded attributes will be saved to the database.
  * Note, validation is not performed in this method. You may call {@link validate} to perform the validation.
  * @param array $attributes list of attributes that need to be saved. Defaults to null,
  * meaning all attributes that are loaded from DB will be saved.
  * @param boolean modify if set true only selected attributes will be replaced, and not
  * the whole document
  * @return boolean whether the update is successful
  * @throws CException if the record is new
  * @throws EMongoException on fail of update
  * @throws MongoCursorException on fail of update, when safe flag is set to true
  * @throws MongoCursorTimeoutException on timeout of db operation , when safe flag is set to true
  * @since v1.0
  */
 public function update(array $attributes = null, $modify = false)
 {
     if ($this->_partial) {
         $attributes = count($attributes) > 0 ? array_intersect($attributes, $this->_loadedFields) : array_diff($this->_loadedFields, array('_id'));
         return parent::update($attributes, true);
     }
     return parent::update($attributes, $modify);
 }