method

pluck

pluck(column_name)
public

This method is designed to perform select by a single column as direct SQL query Returns Array with values of the specified column name The values has same data type as column.

Examples:

Person.pluck(:id) # SELECT people.id FROM people
Person.uniq.pluck(:role) # SELECT DISTINCT role FROM people
Person.where(:confirmed => true).limit(5).pluck(:id)

1Note

Text improvement

xlembouras ยท Mar 10, 2021

The statement about not loading a bunch of records is correct because pluck returns an Array of values, not a ActiveRecord::Relation or an Array of Records.

The exact wording though may be:

"...without retrieving from the database unused columns or loading a bunch of records just to grab the attributes you want"