My query is as shown below :
db.test.findAll({
group: ['source'],
attributes: ['source', [Sequelize.fn('COUNT', 'source'), 'count']],
order: [
[Sequelize.literal('count'), 'DESC']
]
}).then((sources) => {
sources.forEach((info) => {
console.log('sorce name :' + info.source + " count : " + info.count);
})
}).catch((err) => {
console.log(err);
})
So, here what happens is info.source
name is printed perfectly. But info.count
is undefined
even if it is shown in the response ?
Sequelize is trying to map result to test
model, use raw: true
to prevent that...
db.test.findAll({
group: ['source'],
attributes: ['source', [Sequelize.fn('COUNT', 'source'), 'count']],
order: [
[Sequelize.literal('count'), 'DESC']
],
raw: true, // <-- HERE
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With