I have the following model
class Request < ActiveRecord::Base
# Enumerables
enum status: [:pending, :accepted, :completed]
end
and the migration looks like this:
class CreateRequests < ActiveRecord::Migration
def change
create_table :requests do |t|
t.column :status, :integer, default: 0, index: true
end
end
end
Simplified, for the sake for the question.
Now, everything about my Enums works fine.
@request.pending?
@request.accepted!
# And so on...
But when I do the following query:
Request.where(status: :accepted)
This is what my log shows:
SELECT "requests".* FROM "requests" WHERE "requests"."status" = NULL LIMIT 20 OFFSET 0
This is obviously wrong, because of the NULL
. Now I know I could do this
Request.accepted
But the other way should work as well, as explained in the documentation.
What is happening??