0

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?

1 Answer 1

2

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']
  ]
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I'll upgrade to v2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.