Skip to content

Commit

Permalink
Fixed: #125
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammaye committed Sep 27, 2013
1 parent ff0f4a3 commit 61d059e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions EMongoDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,17 +530,23 @@ public function update($attributes=null){
if($this->{$this->primaryKey()} === null) // An _id is required
throw new CDbException(Yii::t('yii', 'The active record cannot be updated because it has no _id.'));

if($attributes !== null)
$partial=false;
if($attributes !== null){
$attributes = $this->filterRawDocument($attributes);
elseif($this->getIsPartial()){
$partial=true;
}elseif($this->getIsPartial()){
foreach($this->_projected_fields as $field => $v)
$attributes[$field] = $this->$field;
$attributes = $this->filterRawDocument($attributes);
$partial=true;
}else
$attributes = $this->getRawDocument();
unset($attributes['_id']); // Unset the _id before update

$this->lastError = $this->updateByPk($this->{$this->primaryKey()}, array('$set' => $attributes));
if($partial===true)
$this->lastError = $this->updateByPk($this->{$this->primaryKey()}, array('$set' => $attributes));
else // If this is not partial then we replace entire doc
$this->lastError = $this->updateByPk($this->{$this->primaryKey()}, $attributes);
$this->afterSave();
return true;
}
Expand Down

0 comments on commit 61d059e

Please sign in to comment.