Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 205
alexs333 Avatar asked Nov 21 '16 00:11

alexs333


1 Answers

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]
like image 155
hibariya Avatar answered Oct 22 '22 09:10

hibariya