不要怂,就是干,撸起袖子干!

Commit f3795742 by José Moreira

Instance.get: Patch

1 parent 5acd3542
Showing with 9 additions and 5 deletions
...@@ -182,10 +182,12 @@ module.exports = (function() { ...@@ -182,10 +182,12 @@ module.exports = (function() {
if (options && options.plain && this.options.include && this.options.includeNames.indexOf(key) !== -1) { if (options && options.plain && this.options.include && this.options.includeNames.indexOf(key) !== -1) {
if (Array.isArray(this.dataValues[key])) { if (Array.isArray(this.dataValues[key])) {
return this.dataValues[key].map(function (instance) { return this.dataValues[key].map(function (instance) {
return instance.get({plain: options.plain}); return instance instanceof Instance ? instance.get({plain: options.plain}) : instance;
}); });
} else { } else if ( this.dataValues[key] instanceof Instance ) {
return this.dataValues[key].get({plain: options.plain}); return this.dataValues[key].get({plain: options.plain});
} else {
return this.dataValues[key];
} }
} }
return this.dataValues[key]; return this.dataValues[key];
...@@ -208,10 +210,12 @@ module.exports = (function() { ...@@ -208,10 +210,12 @@ module.exports = (function() {
if (options && options.plain && this.options.include && this.options.includeNames.indexOf(_key) !== -1) { if (options && options.plain && this.options.include && this.options.includeNames.indexOf(_key) !== -1) {
if (Array.isArray(this.dataValues[_key])) { if (Array.isArray(this.dataValues[_key])) {
values[_key] = this.dataValues[_key].map(function (instance) { values[_key] = this.dataValues[_key].map(function (instance) {
return instance.get({plain: options.plain}); return instance instanceof Instance ? instance.get({plain: options.plain}) : instance;
}); });
} else { } else if ( this.dataValues[_key] instanceof Instance ) {
values[_key] = this.dataValues[_key].get({plain: options.plain}); values[_key] = this.dataValues[_key].get({plain: options.plain});
} else {
values[_key] = this.dataValues[_key];
} }
} else { } else {
values[_key] = this.dataValues[_key]; values[_key] = this.dataValues[_key];
......
...@@ -1200,7 +1200,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -1200,7 +1200,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
}) })
it.only('dont return instance that is not defined', function ( done ) { it('dont return instance that is not defined', function ( done ) {
var self = this; var self = this;
self.Project.create({ lovelyUserId: null }) self.Project.create({ lovelyUserId: null })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!