Only save schema props
This commit is contained in:
parent
605a750859
commit
ba75af1490
19
lib/model.js
19
lib/model.js
|
@ -132,8 +132,11 @@ AbstractClass.defineProperty = function (prop, params) {
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractClass.whatTypeName = function (propName) {
|
AbstractClass.whatTypeName = function (propName) {
|
||||||
var ds = this.schema.definitions[this.modelName];
|
var prop = this.schema.definitions[this.modelName].properties[propName];
|
||||||
return ds.properties[propName] && ds.properties[propName].type.name;
|
if (!prop || !prop.type) {
|
||||||
|
throw new Error('Undefined type for ' + this.modelName + ':' + propName);
|
||||||
|
}
|
||||||
|
return prop.type.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractClass._forDB = function (data) {
|
AbstractClass._forDB = function (data) {
|
||||||
|
@ -233,7 +236,7 @@ AbstractClass.create = function (data, callback) {
|
||||||
obj.trigger('create', function(createDone) {
|
obj.trigger('create', function(createDone) {
|
||||||
obj.trigger('save', function(saveDone) {
|
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) {
|
if (id) {
|
||||||
obj.__data.id = id;
|
obj.__data.id = id;
|
||||||
obj.__dataWas.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 (!data.id) return this.create(data, callback);
|
||||||
if (this.schema.adapter.updateOrCreate) {
|
if (this.schema.adapter.updateOrCreate) {
|
||||||
var inst = new Model(data);
|
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;
|
var obj;
|
||||||
if (data) {
|
if (data) {
|
||||||
inst._initProperties(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
|
* Destroy all records
|
||||||
* @param {Function} cb - callback called with (err)
|
* @param {Function} cb - callback called with (err)
|
||||||
|
|
Loading…
Reference in New Issue