-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Query
-
None
-
Fully Compatible
https://til.hashrocket.com/posts/wcwerkn2il-rails-6-new-activerecord-method-pick
Rails 6 includes 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
pick(:name) is basically equivalent to limit(1).pluck(:name).first.
Like pluck, pick(:name) returns a scalar value and pick(:name, :email) returns an array of values.