Commit e45282c388e99ed24da8666d0d43232c859d3c7b

Authored by 陈亮
1 parent 379112bc

fixed 'only' bugs

lib/Instance.js
@@ -8,6 +8,7 @@ exports.Instance = Instance; @@ -8,6 +8,7 @@ exports.Instance = Instance;
8 function Instance(Model, opts) { 8 function Instance(Model, opts) {
9 opts = opts || {}; 9 opts = opts || {};
10 opts.data = opts.data || {}; 10 opts.data = opts.data || {};
  11 + opts.only = opts.only || [];
11 opts.extra = opts.extra || {}; 12 opts.extra = opts.extra || {};
12 opts.keys = opts.keys || "id"; 13 opts.keys = opts.keys || "id";
13 opts.changes = (opts.is_new ? Object.keys(opts.data) : []); 14 opts.changes = (opts.is_new ? Object.keys(opts.data) : []);
@@ -493,7 +494,7 @@ function Instance(Model, opts) { @@ -493,7 +494,7 @@ function Instance(Model, opts) {
493 } else if (prop && 'defaultValue' in prop) { 494 } else if (prop && 'defaultValue' in prop) {
494 defaultValue = prop.defaultValue; 495 defaultValue = prop.defaultValue;
495 } 496 }
496 - if(opts.data=={} || key in opts.data) 497 + if(opts.only.length==0 || key in opts.only)
497 { 498 {
498 setInstanceProperty(key, defaultValue); 499 setInstanceProperty(key, defaultValue);
499 500
lib/Model.js
@@ -418,7 +418,8 @@ function Model(opts) { @@ -418,7 +418,8 @@ function Model(opts) {
418 autoFetchLimit : options.autoFetchLimit, 418 autoFetchLimit : options.autoFetchLimit,
419 cascadeRemove : options.cascadeRemove, 419 cascadeRemove : options.cascadeRemove,
420 extra : options.extra, 420 extra : options.extra,
421 - extra_info : options.extra_info 421 + extra_info : options.extra_info,
  422 + only : options.only
422 }, cb); 423 }, cb);
423 }, cb); 424 }, cb);
424 } 425 }