Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update_column method for multiple attributes

I have a Model with some attributes: attr1, attr2 and attr3. I need to update this attributes without execute callbacks and validations. I found update_column method but I want to update the three attributes at the same time. I need something like:

update_columns({attr1: val1, attr2: val2, attr3: val3})

instead

update_column(attr1, val1)
update_column(attr2, val2)
update_column(attr3, val3)
like image 891
Leantraxxx Avatar asked Jul 30 '13 19:07

Leantraxxx


2 Answers

You can use update_columns(attr1: val1, attr2: val2, attr3: val3) as documented here. You just need to pass in the key-value pairs, not an actual hash object.

like image 197
Josh Kovach Avatar answered Sep 26 '22 23:09

Josh Kovach


Try this:

update_attributes!(attr1: val1, attr2: val2, attr3: val3)

Perhaps without the !, but I think that is needed.

like image 29
Eugene Avatar answered Sep 25 '22 23:09

Eugene