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

Commit a6d8d0fb by Mick Hansen

fix(instance): plain: true should take array includes into account

1 parent 69e797e6
Showing with 14 additions and 2 deletions
...@@ -180,8 +180,14 @@ module.exports = (function() { ...@@ -180,8 +180,14 @@ module.exports = (function() {
return this._customGetters[key].call(this, key); return this._customGetters[key].call(this, key);
} }
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])) {
return this.dataValues[key].map(function (instance) {
return instance.get({plain: options.plain});
});
} else {
return this.dataValues[key].get({plain: options.plain}); return this.dataValues[key].get({plain: options.plain});
} }
}
return this.dataValues[key]; return this.dataValues[key];
} }
...@@ -200,7 +206,13 @@ module.exports = (function() { ...@@ -200,7 +206,13 @@ module.exports = (function() {
for (_key in this.dataValues) { for (_key in this.dataValues) {
if (!values.hasOwnProperty(_key) && this.dataValues.hasOwnProperty(_key)) { if (!values.hasOwnProperty(_key) && this.dataValues.hasOwnProperty(_key)) {
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])) {
values[_key] = this.dataValues[_key].map(function (instance) {
return instance.get({plain: options.plain});
});
} else {
values[_key] = this.dataValues[_key].get({plain: options.plain}); values[_key] = this.dataValues[_key].get({plain: options.plain});
}
} else { } else {
values[_key] = this.dataValues[_key]; values[_key] = this.dataValues[_key];
} }
...@@ -298,7 +310,7 @@ module.exports = (function() { ...@@ -298,7 +310,7 @@ module.exports = (function() {
} else { } else {
// Check if we have included models, and if this key matches the include model names/aliases // Check if we have included models, and if this key matches the include model names/aliases
if (this.options.include && this.options.includeNames.indexOf(key) !== -1 && value) { if (this.options && this.options.include && this.options.includeNames.indexOf(key) !== -1 && value) {
// Pass it on to the include handler // Pass it on to the include handler
this._setInclude(key, value, options); this._setInclude(key, value, options);
return; return;
...@@ -332,7 +344,7 @@ module.exports = (function() { ...@@ -332,7 +344,7 @@ module.exports = (function() {
// Bit fields are returned as buffers // Bit fields are returned as buffers
value = value[0]; value = value[0];
} }
value = _.isString(value) ? !!parseInt(value) : !!value; value = _.isString(value) ? !!parseInt(value, 10) : !!value;
} }
if (!options.raw && originalValue !== value) { if (!options.raw && originalValue !== value) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!