Browse Source

Adding fix on update

Paolo Libertini 6 years ago
parent
commit
271503a1ec
1 changed files with 5 additions and 2 deletions
  1. 5 2
      lib/Mooses/AbstractMongo.php

+ 5 - 2
lib/Mooses/AbstractMongo.php

@@ -381,8 +381,10 @@ class Mooses_AbstractMongo extends Mooses_Mongodb_Mongo_Document {
 
     protected function ___load($_value, $_attributeName = NULL){
         if(is_null($_attributeName)){
+            $this->loadKey = ['_id' => new MongoId($_value)];
             return parent::find($_value);
         } else {
+            $this->loadKey = array($_attributeName => $_value);
             return parent::fetchOne(array($_attributeName => $_value));
         }
     }
@@ -412,8 +414,9 @@ class Mooses_AbstractMongo extends Mooses_Mongodb_Mongo_Document {
         return $result;
     }
 
-    public function updateData(){
-        $_return = $this->update($this->loadKey, array('$set' => $this->_dataUpdate));
+    public function updateData($_criteria = false){
+        $_criteria = $_criteria ?: $this->loadKey;
+        $_return = $this->update($_criteria, array('$set' => $this->_dataUpdate));
         return $_return;
     }