gpt4 book ai didi

node.js - sequelize.fn 不同的值没有给出条件的所有列

转载 作者:行者123 更新时间:2023-12-03 22:18:42 25 4
gpt4 key购买 nike

我的查询如下所示:

db.orderUser.findAll({
where: {partner_id: req.user.id},
attributes: [
[Sequelize.fn('DISTINCT', Sequelize.col('user_email')), 'user_email'],
]
}).then((info) => {
response.sendsuccessData(res, 'Your user contact list', info);
})

结果,我只得到 user_email 列。那么有没有办法获得标准的所有列?

最佳答案

您可以通过从 concat 获取值来对值进行 Model.rawAttributes

const User = sequelize.define('User', {
username: Sequelize.STRING,
name: Sequelize.STRING
});

sequelize.sync({ force: true })
.then(() => {
User.create({
username: 'test123',
name: 'test'
})
.then(() => {
User.findAll({
attributes: [
[Sequelize.fn('DISTINCT', Sequelize.col('username')), 'username'],
].concat(Object.keys(User.rawAttributes)),
}).then((res) => {
console.log(res);
});
});
});

关于node.js - sequelize.fn 不同的值没有给出条件的所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50673653/

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