Permalink
Browse files

Only save schema props

  • Loading branch information...
1 parent d8897a5 commit 870bb6603abfc928f0cbf22251cae77fa886b9fa @1602 committed Apr 23, 2013
Showing with 7 additions and 12 deletions.
  1. +7 −12 lib/model.js
View
@@ -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)

0 comments on commit 870bb66

Please sign in to comment.