diff --git a/lib/Model.js b/lib/Model.js index 0e2a78d..4296614 100644 --- a/lib/Model.js +++ b/lib/Model.js @@ -72,15 +72,19 @@ var Model = module.exports = Class.extend({ each: function each(options, callback) { var then; - this.db.find(this, options, function (err, results) { - if (err) throw err; - if (results.length) { - results.forEach(callback); - } - if (then) { - then(); - } + var self = this; + setImmediate(function () { + self.db.find(self, options, function (err, results) { + if (err) throw err; + if (results.length) { + results.forEach(callback); + } + if (then) { + then(); + } + }); }); + // TODO: Implement real promises. return {then: function (callback) { then = callback; }}; }, diff --git a/package.json b/package.json index a5027b6..032b6d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ormy", - "version": "0.2.2", + "version": "0.2.3", "description": "Easy data models", "dependencies": { "mysql": "2.4.2",