Commit 4d9755dd105c6e724061c13dee3e76a864e0b535

Authored by 陈亮
1 parent f6737d52

remove omit prop when create instance

Showing 1 changed file with 26 additions and 24 deletions
lib/Instance.js
@@ -493,34 +493,36 @@ function Instance(Model, opts) { @@ -493,34 +493,36 @@ function Instance(Model, opts) {
493 } else if (prop && 'defaultValue' in prop) { 493 } else if (prop && 'defaultValue' in prop) {
494 defaultValue = prop.defaultValue; 494 defaultValue = prop.defaultValue;
495 } 495 }
  496 + if(opts.data=={} || key in opts.data)
  497 + {
  498 + setInstanceProperty(key, defaultValue);
  499 +
  500 + Object.defineProperty(instance, key, {
  501 + get: function () {
  502 + return opts.data[key];
  503 + },
  504 + set: function (val) {
  505 + if (prop.key === true) {
  506 + if (prop.type == 'serial' && opts.data[key] != null) {
  507 + return;
  508 + } else {
  509 + opts.originalKeyValues[prop.name] = opts.data[prop.name];
  510 + }
  511 + }
496 512
497 - setInstanceProperty(key, defaultValue);  
498 -  
499 - Object.defineProperty(instance, key, {  
500 - get: function () {  
501 - return opts.data[key];  
502 - },  
503 - set: function (val) {  
504 - if (prop.key === true) {  
505 - if (prop.type == 'serial' && opts.data[key] != null) { 513 + if (!setInstanceProperty(key, val)) {
506 return; 514 return;
507 - } else {  
508 - opts.originalKeyValues[prop.name] = opts.data[prop.name];  
509 } 515 }
510 - }  
511 516
512 - if (!setInstanceProperty(key, val)) {  
513 - return;  
514 - }  
515 -  
516 - if (opts.autoSave) {  
517 - saveInstanceProperty(key, val);  
518 - } else if (opts.changes.indexOf(key) === -1) {  
519 - opts.changes.push(key);  
520 - }  
521 - },  
522 - enumerable: true  
523 - }); 517 + if (opts.autoSave) {
  518 + saveInstanceProperty(key, val);
  519 + } else if (opts.changes.indexOf(key) === -1) {
  520 + opts.changes.push(key);
  521 + }
  522 + },
  523 + enumerable: true
  524 + });
  525 + }
524 }; 526 };
525 var addInstanceExtraProperty = function (key) { 527 var addInstanceExtraProperty = function (key) {
526 if (!instance.hasOwnProperty("extra")) { 528 if (!instance.hasOwnProperty("extra")) {