Skip to content

Commit

Permalink
Fixed model.remove ignoring callback
Browse files Browse the repository at this point in the history
I don't know if this behavior was intended, but it's wrong. 
If I call .remove on the same model twice for whatever reason, second call will never execute callback, which will break execution flow.
  • Loading branch information
bratchenko committed Nov 13, 2012
1 parent 6eecdad commit 1ef516b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 661,7 @@ Model.prototype._where = function _where (where) {
*/

Model.prototype.remove = function remove (fn) {
if (this._removing) return this;

var promise = this._removing = new Promise(fn)
var promise = new Promise(fn)
, where = this._where()
, self = this
, options = {}
Expand All @@ -675,7 673,7 @@ Model.prototype.remove = function remove (fn) {
this.collection.remove(where, options, tick(function (err) {
if (err) {
promise.error(err);
promise = self = self._removing = where = options = null;
promise = self = where = options = null;
return;
}
self.emit('remove', self);
Expand Down

0 comments on commit 1ef516b

Please sign in to comment.