diff --git a/lib/Instance.js b/lib/Instance.js index c7b4748..3cb525a 100644 --- a/lib/Instance.js +++ b/lib/Instance.js @@ -70,10 +70,10 @@ function Instance(collection, doc, options, isNew) { if (targetProperty === '_id' || targetProperty === "id") continue; (function (sourceProperty) { - if (k === '_id') + if (sourceProperty === '_id' || sourceProperty === 'id') Object.defineProperty($, targetProperty, { get: function () { - return newDoc[sourceProperty]; + return newDoc['_id']; }, enumerable: true }); @@ -100,8 +100,10 @@ function Instance(collection, doc, options, isNew) { } for (k in options.methods) { + if (k === '_id' || k === "id") continue; + (function (sourceProperty) { - Object.defineProperty($, k, { + Object.defineProperty($, sourceProperty, { value: function () { return options.methods[sourceProperty].apply($, arguments); } @@ -110,8 +112,10 @@ function Instance(collection, doc, options, isNew) { } for (k in options.virtuals) { + if (k === '_id' || k === "id") continue; + (function (sourceProperty) { - Object.defineProperty($, k, { + Object.defineProperty($, sourceProperty, { get: function () { return options.virtuals[sourceProperty].call($); } @@ -211,8 +215,13 @@ function Instance(collection, doc, options, isNew) { Object.defineProperty($, 'update', { value: function (callback) { + /// + /// Updates this object from the database, bringing it up to date + /// + /// /// Updates this object from the database, bringing it up to date /// A function to be called once the update is complete + /// var conditions = { _id: $.id }; @@ -224,7 +233,8 @@ function Instance(collection, doc, options, isNew) { transform.down(options.transforms, updated); oldDoc = newDoc = updated; - return callback(null, $); + + if(callback) return callback(null, $); }); } }); diff --git a/lib/Model.js b/lib/Model.js index 56d3f51..4e42946 100644 --- a/lib/Model.js +++ b/lib/Model.js @@ -227,12 +227,14 @@ Model.prototype.remove = function (conditions, callback) { this.collection.remove(conditions, { w: callback ? 1 : 0 }, callback); }; -Model.prototype.aggregate = function (chain, callback) { +Model.prototype.aggregate = function () { + /// /// Allows you to execute aggregation queries using MongoDB's aggregation framework /// The aggregation toolchain to run /// A function to be called once aggregation has been completed - - this.collection.aggregate(chain, callback); + /// + + this.collection.aggregate.apply(this.collection, arguments); }; Model.prototype.ensureIndex = function (spec, options, callback) {