Danilo.Micucci
Danilo.Micucci

Reputation: 83

Change value in a model, adding upon what's written

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!

Upvotes: 0

Views: 55

Answers (1)

cschroed
cschroed

Reputation: 6889

You could use a little bit of SQL in the update_all call like:

Dealer.update_all(['name = CONCAT(name, ?)', '__old'])

Upvotes: 1

Related Questions