Rails 6 new ActiveRecord method pick
Rails 6 will be released with a new convenient method on ActiveRecord pick. This method picks the first result value(s) from a ActiveRecord relation.
Person.all.pick(:name)
# SELECT people.name FROM people LIMIT 1
# => 'John'
Person.all.pick(:name, :email)
# SELECT people.name, people.email FROM people LIMIT 1
# => ['John', 'john@mail.com']
So pick(:name)
is basically equivalent to limit(1).pluck(:name).first
.
Watch out for rails inconsistencies as pick(:name)
returns a single string value and pick(:name, :email)
returns an array of values.