Only save to database attributes that listed in schema
This commit is contained in:
parent
6238b738e4
commit
35dd198f70
|
@ -102,7 +102,7 @@ AbstractClass.create = function (data) {
|
|||
// if we come from save
|
||||
if (data instanceof AbstractClass && !data.id) {
|
||||
obj = data;
|
||||
data = obj.toObject();
|
||||
data = obj.toObject(true);
|
||||
} else {
|
||||
obj = new this(data);
|
||||
|
||||
|
@ -211,7 +211,7 @@ AbstractClass.prototype.save = function (options, callback) {
|
|||
return callback && callback(err);
|
||||
}
|
||||
var modelName = this.constructor.modelName;
|
||||
var data = this.toObject();
|
||||
var data = this.toObject(true);
|
||||
if (this.id) {
|
||||
this._adapter().save(modelName, data, function (err) {
|
||||
if (err) {
|
||||
|
@ -240,10 +240,12 @@ AbstractClass.prototype.propertyChanged = function (name) {
|
|||
return this[name + '_was'] !== this['_' + name];
|
||||
};
|
||||
|
||||
AbstractClass.prototype.toObject = function () {
|
||||
AbstractClass.prototype.toObject = function (onlySchema) {
|
||||
// blind faith: we only enumerate properties
|
||||
var data = {};
|
||||
Object.keys(this).forEach(function (property) {
|
||||
var ds = this.constructor.schema.definitions[this.constructor.modelName];
|
||||
var properties = ds.properties;
|
||||
Object.keys(onlySchema ? properties : this).concat(['id']).forEach(function (property) {
|
||||
data[property] = this[property];
|
||||
}.bind(this));
|
||||
return data;
|
||||
|
|
Loading…
Reference in New Issue