How to bulk increment integer attribute?
I want to do something like this:
User.update({ clicks: "clicks + 1" }, { type: "member" }).done(...)
This obviously does not work - how I can write clicks = clicks + 1?
Not supported currently. There are atomic updates for instances but that's currently it.
You should be able to this though:
User.update({
clicks: sequelize.literal('clicks +1')
,... )
Perfect, it works :) Thanks For me this is enough and you can close this issue if you want.
That works! Great! :+1:
Thanks !!
No, it's not working. I got this error
Unhandled rejection SequelizeDatabaseError: syntax error at or near "+"
@hebbian You have to give some more context than that if you want us to help you - What code are you running, and what does the query look like at the least?
@janmeier
This command:
like: models.sequelize.literal('like +1')
produce this query
UPDATE "threads" SET "like"=like + 1,"updatedAt"='2016-06-30 08:39:39.012 +00:00' WHERE "id" = '2'
I put that query on pgadmin and it shows error:
ERROR: syntax error at or near "+" LINE 1: UPDATE "threads" SET "like"=like + 1,"updatedAt"='2016-06-30...
Try quoting (") the column name. What is the type of the column?
@janmeier Yes, you're right, I missed that (") point. It's working now.
It's an integer field .
is this still the recommended way to do this or has there been an update?
@ahmadabdul3 Good question, no update that I know of, I will reopen this as a documentation issue, I think this deserves to be added to the docs