From a3c7a0cf09139cc290cb20ed5e2936a16a2a811a Mon Sep 17 00:00:00 2001 From: Jacky Wijaya Date: Tue, 2 Jul 2019 13:49:06 +0700 Subject: [PATCH] fix: bug column name when sequelize model mapping attribute has field option access the schema field columnName instead access directly through the fieldName. Closed #282 Closed #273 --- src/services/line-stat-getter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/services/line-stat-getter.js b/src/services/line-stat-getter.js index 23153455..56aae138 100644 --- a/src/services/line-stat-getter.js +++ b/src/services/line-stat-getter.js @@ -17,12 +17,16 @@ function LineStatGetter(model, params, options) { // cannot be '*'. const fieldName = params.aggregate_field || schema.primaryKeys[0] || schema.fields[0].field; - return `${schema.name}.${fieldName}`; + const schemaField = schema.fields.find(schemaField => schemaField.field === fieldName); + const columnName = schemaField ? schemaField.columnName : fieldName; + return `${schema.name}.${columnName}`; } function getGroupByDateField() { const fieldName = params.group_by_date_field; - return `${schema.name}.${fieldName}`; + const schemaField = schema.fields.find(schemaField => schemaField.field === fieldName); + const columnName = schemaField ? schemaField.columnName : fieldName; + return `${schema.name}.${columnName}`; } const groupByDateField = getGroupByDateField();