I'm using Rails 5.2.
I want to pluck an enum field and get an array of integers.
class Foo < ApplicationRecord
enum bar: { val1: 1, val2: 2 }
end
Foo.pluck(:bar) #=> ['val1', 'val2']
Foo.pluck('foos.bar') #=> ['val1', 'val2']
Foo.pluck(:bar_before_type_cast) #=> DB error!
I can write it like Foo.pluck(:bar).map {|bar| Foo.bars[bar]} , but I want to write it more shortly.
How to achieve this?