From ba75af149099aafd6db6a0ea9511092f65b7e614 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Tue, 23 Apr 2013 18:10:56 +0400 Subject: [PATCH] Only save schema props --- lib/model.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/model.js b/lib/model.js index 91f98431..f1297a61 100644 --- a/lib/model.js +++ b/lib/model.js @@ -132,8 +132,11 @@ AbstractClass.defineProperty = function (prop, params) { }; AbstractClass.whatTypeName = function (propName) { - var ds = this.schema.definitions[this.modelName]; - return ds.properties[propName] && ds.properties[propName].type.name; + var prop = this.schema.definitions[this.modelName].properties[propName]; + if (!prop || !prop.type) { + throw new Error('Undefined type for ' + this.modelName + ':' + propName); + } + return prop.type.name; }; AbstractClass._forDB = function (data) { @@ -233,7 +236,7 @@ AbstractClass.create = function (data, callback) { obj.trigger('create', function(createDone) { obj.trigger('save', function(saveDone) { - this._adapter().create(modelName, this.constructor._forDB(obj.toObject()), function (err, id, rev) { + this._adapter().create(modelName, this.constructor._forDB(obj.toObject(true)), function (err, id, rev) { if (id) { obj.__data.id = id; obj.__dataWas.id = id; @@ -279,7 +282,7 @@ AbstractClass.upsert = AbstractClass.updateOrCreate = function upsert(data, call if (!data.id) return this.create(data, callback); if (this.schema.adapter.updateOrCreate) { var inst = new Model(data); - this.schema.adapter.updateOrCreate(Model.modelName, inst.toObject(), function (err, data) { + this.schema.adapter.updateOrCreate(Model.modelName, inst.toObject(true), function (err, data) { var obj; if (data) { inst._initProperties(data); @@ -434,14 +437,6 @@ AbstractClass.findOne = function findOne(params, cb) { }); }; -function substractDirtyAttributes(object, data) { - Object.keys(object.toObject()).forEach(function (attr) { - if (data.hasOwnProperty(attr) && object.propertyChanged(attr)) { - delete data[attr]; - } - }); -} - /** * Destroy all records * @param {Function} cb - callback called with (err)