module ActiveRecord::Calculations
def pick(*column_names)
# SELECT people.name, people.email_address FROM people WHERE id = 1 LIMIT 1
Person.where(id: 1).pick(:name, :email_address)
# => 'David'
# SELECT people.name FROM people WHERE id = 1 LIMIT 1
Person.where(id: 1).pick(:name)
more efficient. The value is, again like with pluck, typecast by the column type.
Just like #pluck, #pick will only load the actual value, not the entire record object, so it's also
when you have a relation that's already narrowed down to a single row.
This is short-hand for relation.limit(1).pluck(*column_names).first, and is primarily useful
Pick the value(s) from the named column(s) in the current relation.
def pick(*column_names) if loaded? && all_attributes?(column_names) return records.pick(*column_names) end limit(1).pluck(*column_names).first end