I have a model called Dealers, and there's a bunch of dealers (which contain the value name).
And I would like to update all these dealers all at once, but I would like to add the string "__old" to all these Dealers.
I know I could use an update_all
, but that would change all the value's to __old which is not the objective. Is there a way to update the values, maintaining the old name and adding the new value?
Thanks a lot for your help! Very appreciated!
CodePudding user response:
You could use a little bit of SQL in the update_all
call like:
Dealer.update_all(['name = CONCAT(name, ?)', '__old'])