1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// Convert column name of joined table. // If released new option, remove below function. // e.g Table.column => column or tableColumn const convertResultsColumnName = (results) => { if (results) { if (Array.isArray(results)) { results.forEach(result => convertColumnNameFormat(result)); } else { convertColumnNameFormat(results); } } }; const convertColumnNameFormat = (item) => { Object.keys(item).filter(key => key.includes('.')).forEach(key => { const [table, column] = key.split('.'); const newKey = item[column] === undefined ? column : (table.charAt(0).toLowerCase() + table.slice(1) + column.charAt(0).toUpperCase() + column.slice(1)); item[newKey] = item[key]; delete item[key]; }); }; sequelize.addHook('afterFind', convertResultsColumnName); |
need to setting
1 |
options.raw = true |