Search code examples
ruby-on-railsruby-on-rails-5

How to update a rails table column with values based on current values


I have a Match model, with a field called effective_from. Every entry in this column is different. I would like to increase each entry by 10 hours e.g. + (36000). I can see how to update_all values of a column, but that shows how to change all values to the same value

I have tried a few things including

Match.update_all(effective_from: Match.pluck(:effective_from) + 36000))

But I can't quite get it


Solution

  • Resort to SQL:

    Match.update_all('effective_from = effective_from + 36000')