Reputation: 7944
I'm trying to do some calculations with a field and select the value. In my attributes I have:
attributes: ['username', 'last_activity', '(last_activity - 1000) as test']
That doesn't work, since it encloses the SQL in quotes.
How can I do something like this with Sequelize?
Upvotes: 0
Views: 297
Reputation: 28778
With v2.0.0dev12 you can do:
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']
]
});
Upvotes: 2