ActiveRecord::Calculations#pluck accepts multiple columns#6500
ActiveRecord::Calculations#pluck accepts multiple columns#6500jeroeningen wants to merge 3 commits into
Conversation
|
Mentioning #5472 so that GitHub links them. |
There was a problem hiding this comment.
Columns need to be typecasted in both scenarios, otherwise pluck would work differently when using 1 and more columns.
|
I think we should probably have this feature as people keep asking about it. However I think we should decide between |
|
@carlos, you were right with your comment my mistakes. Just fixed and pushed it! @jon In my previous pull request, several people liked it (see #5472). So IMO that's not the problem. But why do you want to support just one of the possibilities of Post.pluck([:a, :b]) and Post.pluck(:a, :b) and not both? |
|
@jeroeningen I've pulled your changes and modified as per @jonleighton comments: d59b2ab. Thanks for your work on that :). |
|
How about if |
Ensure it works with mix of symbols and strings, and with a select
clause possibly containing more than one column.
Also remove support for pluck with an array of columns, in favor of
passing the list of attributes:
Model.pluck(:a, :b)
See comments: rails#6500 (comment)
Rails currently supports this:
Person.pluck(:id) # SELECT people.id FROM people
I added two possibilities:
Person.pluck(:id) # SELECT people.id FROM people
Person.pluck([:id, :name]) # SELECT people.id, people.name FROM people
Person.pluck(:id, :name) # SELECT people.id, people.name FROM people
Because I made some stupid mistakes while updating my own fork of rails/rails this is a new fork and a follow up of the discussion located here: #5472