diff --git a/lib/Model.js b/lib/Model.js index 804bcdb..8847b91 100644 --- a/lib/Model.js +++ b/lib/Model.js @@ -138,18 +138,6 @@ Model.prototype.find = function (conditions, callback) { var $ = this; if (!_.isPlainObject(conditions)) conditions = { _id: conditions }; - // Handle any renames - for(var upstream in this.options.rename) { - var downstream = this.options.rename[upstream]; - - if(conditions.hasOwnProperty(upstream)) { - if(conditions.hasOwnProperty(downstream)) delete conditions[downstream]; - } else if(conditions.hasOwnProperty(downstream)) { - conditions[upstream] = conditions[downstream]; - delete conditions[downstream]; - } - } - this.toSource(conditions); this.collection.find(conditions).toArray(function (err, results) { @@ -183,18 +171,6 @@ Model.prototype.findOne = Model.prototype.get = function (conditions, callback) var $ = this; if (!_.isPlainObject(conditions)) conditions = { _id: conditions }; - // Handle any renames - for(var upstream in this.options.rename) { - var downstream = this.options.rename[upstream]; - - if(conditions.hasOwnProperty(upstream)) { - if(conditions.hasOwnProperty(downstream)) delete conditions[downstream]; - } else if(conditions.hasOwnProperty(downstream)) { - conditions[upstream] = conditions[downstream]; - delete conditions[downstream]; - } - } - this.toSource(conditions); this.collection.findOne(conditions, function (err, results) { @@ -265,21 +241,9 @@ Model.prototype.insert = Model.prototype.create = function (object, callback) { if(err) return prepNext(err); // Validate the object - var validation = validate($.options.schema, obj, $.extraValidators); + var validation = validate($.schema, obj, undefined, $.extraValidators); if(!validation.passed) return prepNext(validation.toError()); - // Handle any renames - for(var upstream in $.options.rename) { - var downstream = $.options.rename[upstream]; - - if(obj.hasOwnProperty(upstream)) { - if(obj.hasOwnProperty(downstream)) delete obj[downstream]; - } else if(obj.hasOwnProperty(downstream)) { - obj[upstream] = obj[downstream]; - delete obj[downstream]; - } - } - // Transform the object $.toSource(obj); @@ -315,18 +279,6 @@ Model.prototype.update = function (conditions, changes, callback) { /// A function to be called once the update has completed /// - // Handle any renames - for(var upstream in this.options.rename) { - var downstream = this.options.rename[upstream]; - - if(conditions.hasOwnProperty(upstream)) { - if(conditions.hasOwnProperty(downstream)) delete conditions[downstream]; - } else if(conditions.hasOwnProperty(downstream)) { - conditions[upstream] = conditions[downstream]; - delete conditions[downstream]; - } - } - this.toSource(conditions); this.collection.update(conditions, changes, { w: callback ? 1 : 0, multi: true }, callback); @@ -348,18 +300,6 @@ Model.prototype.count = function (conditions, callback) { conditions = {}; } - // Handle any renames - for(var upstream in this.options.rename) { - var downstream = this.options.rename[upstream]; - - if(conditions.hasOwnProperty(upstream)) { - if(conditions.hasOwnProperty(downstream)) delete conditions[downstream]; - } else if(conditions.hasOwnProperty(downstream)) { - conditions[upstream] = conditions[downstream]; - delete conditions[downstream]; - } - } - this.toSource(conditions); this.collection.count(conditions, callback); @@ -388,18 +328,6 @@ Model.prototype.remove = function (conditions, callback) { if (!_.isPlainObject(conditions)) conditions = { _id: conditions }; - // Handle any renames - for(var upstream in this.options.rename) { - var downstream = this.options.rename[upstream]; - - if(conditions.hasOwnProperty(upstream)) { - if(conditions.hasOwnProperty(downstream)) delete conditions[downstream]; - } else if(conditions.hasOwnProperty(downstream)) { - conditions[upstream] = conditions[downstream]; - delete conditions[downstream]; - } - } - this.toSource(conditions); this.collection.remove(conditions, { w: callback ? 1 : 0 }, callback);