How to make active record queries when attributes uses enumerize

449 Views Asked by At
class AppointmentResponse < ActiveRecord::Base
...
  extend Enumerize
  enumerize :status, in: %i[unreviewed approved rejected], default: :unreviewed
...
end

Migration:

def change
   add_column :appointment_responses, :status, :string
end

So with this, my thinking is that I should be able to make queries like:

AppointmentResponse.where(status: :unreviewed)

But this returns: []

But I know that to be false. Exibit A:

 #<AppointmentResponse:0x007feb02c5d290
  id: 16,
  ...
  status: "unreviewed">

And I can confirm that I haven't made some terrible character error by:

AppointmentResponse.last.status == "unreviewed"

true

What am I missing? I've also switched extend Enumerize to include Enumerize. It's still the same. I've also tried adding scope: true and predicates: true, still no. I know Enumerize works with active record. What am I doing wrong?

1

There are 1 best solutions below

0
On

I figured it out I needed to added to the migration:

def change add_column :appointment_responses, :status, :string, default: 'unreviewed' end