activerecord - Ruby on rails active record: update a field by another field in the same record using update_all -
how can use update_all following purpose:
update table_name set field1=field2 * 2 id = 1
in rails4, can do
model.where(id: 1).update_all("field = field2 * 2")
in previous versions of rails, can pass condition update_all
, this
model.update_all("field = field2 * 2", {:id => 1})
note:
update_all not trigger active record callbacks or validations
Comments
Post a Comment