gpt4 book ai didi

javascript - sequelize group by fn count 变得未定义

转载 作者:搜寻专家 更新时间:2023-11-01 00:50:39 25 4
gpt4 key购买 nike

我的查询如下所示:

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);
})

所以,这里发生的是 info.source 名称被完美打印。但是 info.countundefined 即使它显示在响应中?

最佳答案

Sequelize 正在尝试将结果映射到test 模型,使用raw: true 来防止...

db.test.findAll({
group: ['source'],
attributes: ['source', [Sequelize.fn('COUNT', 'source'), 'count']],
order: [
[Sequelize.literal('count'), 'DESC']
],
raw: true, // <-- HERE
})

关于javascript - sequelize group by fn count 变得未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52034955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com