I'm looking for a way to update all record with certain condition their cur_val + 100:
I have a table Suggestions with id and score fields, and I want all the entries with specific ids to receive a score bump, e.g:
Suggestion.where(id: ids_list).update_all(score: score+100)
How do I do that?
Try plain
SQL, read aboutupdate_all:But remember
update_allnot triggerActive Recordcallbacks or validations.Some tips:
You can do it in
Rubybut this very bad:Things like this should happen in database.