我正在尝试使用字段进行一些计算并选择值。在我的属性中,我有:
attributes: ['username', 'last_activity', '(last_activity - 1000) as test']
这不起作用,因为它用引号括起SQL。
如何使用Sequelize做这样的事情?
答案 0 :(得分:2)
使用v2.0.0dev12,您可以:
Model.find({
attributes: [
'username',
'last_activity',
// (last_activity - 1000) as test
Sequelize.literal('(last_activity - 1000) as test')
// (last_activity - 1000) as `test` - the as part is quoted
[Sequelize.literal('(last_activity - 1000)'), 'test']
]
});