alexs333 alexs333 - 14 days ago 6
Ruby Question

Rails - update_column and ActiveRecord enum

I require to use

update_column
in my Rails application to prevent callbacks from being run. I have my ActiveRecord model with enum:

class Car < ActiveRecord::Base
enum state: [:not_used, :used]
end


In normal scenario (i.e. when I do want the callbacks to run) I can use something like that:

@car.update_attribute :state, :not_used


Is it possible to do something similar with
update_column
?

I am using Rails 4.2

Answer

update_column doesn't recognize symbols as a variant of the enum. I think that you have to Use Car.states[:not_used] instead of :not_used. Like this:

@car.update_column :state, Car.states[:not_used]
Comments