Permalink
Browse files

fixed issue #2

  • Loading branch information...
1 parent 358a47d commit 7bf2af4234cfcf085135e4d9afd82b93e17a39af @vadimdemedes committed Feb 26, 2012
Showing with 11 additions and 3 deletions.
  1. +3 −1 lib/mongorito.coffee
  2. +8 −2 lib/mongorito.js
@@ -317,11 +317,13 @@ class MongoritoModel
, (results) ->
return callback yes, results if results.length > 0
- Cache.delByTag that.collection, ->
+ performOperation = ->
if fields._id
that.update callback, yes
else
that.create callback, yes
+
+ if Cache then Cache.delByTag that.collection, performOperation else do performOperation
create: (callback, fromSave = no) ->
object = @fields()
View
@@ -428,14 +428,20 @@ MongoritoModel = (function() {
return nextKey(false);
}
}, function(results) {
+ var performOperation;
if (results.length > 0) return callback(true, results);
- return Cache.delByTag(that.collection, function() {
+ performOperation = function() {
if (fields._id) {
return that.update(callback, true);
} else {
return that.create(callback, true);
}
- });
+ };
+ if (Cache) {
+ return Cache.delByTag(that.collection, performOperation);
+ } else {
+ return performOperation();
+ }
});
};

0 comments on commit 7bf2af4

Please sign in to comment.