InterviewSolution
Saved Bookmarks
| 1. |
Pluck ? |
|
Answer» pluck can be used to query a single COLUMN from the underlying table of a MODEL. It accepts a column name as argument and returns an ARRAY of VALUES of the specified column with the corresponding data type. Client.where(:active => true).pluck(:id) # SELECT id FROM clients WHERE active = 1 Client.uniq.pluck(:role) # SELECT DISTINCT role FROM clientspluck can be used to query a single column from the underlying table of a model. It accepts a column name as argument and returns an array of values of the specified column with the corresponding data type. |
|