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

Commit af489905 by Thaddeus Quintin

Add over-riding 'plain' functionality to aggregate function, along with fixing a…

… typeError when a result was NULL.
1 parent dabefbe8
Showing with 8 additions and 2 deletions
...@@ -746,8 +746,10 @@ module.exports = (function() { ...@@ -746,8 +746,10 @@ module.exports = (function() {
}); });
} }
options.plain = options.plain === undefined ? true : options.plain;
var sql = this.QueryGenerator.selectQuery(tableName, options, Model) var sql = this.QueryGenerator.selectQuery(tableName, options, Model)
, queryOptions = Utils._.extend({ transaction: options.transaction }, { plain: true, raw: true, type: QueryTypes.SELECT }) , queryOptions = Utils._.extend({ transaction: options.transaction, plain: options.plain }, { raw: true, type: QueryTypes.SELECT })
, self = this; , self = this;
if (attributeSelector === undefined) { if (attributeSelector === undefined) {
...@@ -755,6 +757,10 @@ module.exports = (function() { ...@@ -755,6 +757,10 @@ module.exports = (function() {
} }
return this.sequelize.query(sql, null, queryOptions).then(function(data) { return this.sequelize.query(sql, null, queryOptions).then(function(data) {
if (!queryOptions.plain) {
return data;
}
var result = data ? data[attributeSelector] : null; var result = data ? data[attributeSelector] : null;
if (options && options.dataType) { if (options && options.dataType) {
...@@ -765,7 +771,7 @@ module.exports = (function() { ...@@ -765,7 +771,7 @@ module.exports = (function() {
} else if (dataType instanceof DataTypes.INTEGER || dataType instanceof DataTypes.BIGINT) { } else if (dataType instanceof DataTypes.INTEGER || dataType instanceof DataTypes.BIGINT) {
result = parseInt(result, 10); result = parseInt(result, 10);
} else if (dataType instanceof DataTypes.DATE) { } else if (dataType instanceof DataTypes.DATE) {
if (!Utils._.isDate(result)) { if (!Utils._.isNull(result) && !Utils._.isDate(result)) {
result = new Date(result); result = new Date(result);
} }
} else if (dataType instanceof DataTypes.STRING) { } else if (dataType instanceof DataTypes.STRING) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!