New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord::Calculations#pluck accepts multiple columns #6500

Closed
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
5 participants
@jeroeningen

jeroeningen commented May 26, 2012

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

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik May 26, 2012

Member

Mentioning #5472 so that GitHub links them.

Member

steveklabnik commented May 26, 2012

Mentioning #5472 so that GitHub links them.

@jonleighton

This comment has been minimized.

Show comment
Hide comment
@jonleighton

jonleighton May 31, 2012

Member

I think we should probably have this feature as people keep asking about it. However I think we should decide between Post.pluck([:a, :b]) and Post.pluck(:a, :b) and just support one of them. I think probably the latter.

Member

jonleighton commented May 31, 2012

I think we should probably have this feature as people keep asking about it. However I think we should decide between Post.pluck([:a, :b]) and Post.pluck(:a, :b) and just support one of them. I think probably the latter.

@jeroeningen

This comment has been minimized.

Show comment
Hide comment
@jeroeningen

jeroeningen Jun 2, 2012

@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 commented Jun 2, 2012

@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?

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Jun 22, 2012

Member

@jeroeningen I've pulled your changes and modified as per @jonleighton comments: d59b2ab. Thanks for your work on that :).

Member

carlosantoniodasilva commented Jun 22, 2012

@jeroeningen I've pulled your changes and modified as per @jonleighton comments: d59b2ab. Thanks for your work on that :).

@RKushnir

This comment has been minimized.

Show comment
Hide comment
@RKushnir

RKushnir Nov 15, 2012

Contributor

How about if pluck would also account for the select arguments? So Model.select([:id, :name]).pluck would project id and name.

Contributor

RKushnir commented Nov 15, 2012

How about if pluck would also account for the select arguments? So Model.select([:id, :name]).pluck would project id and name.

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Nov 15, 2012

Member

@RKushnir we've just merged a change that will ignore the select values in 3a33572. If you think it can be improved, please feel free to open a new topic in the core mailing list. Thanks.

Member

carlosantoniodasilva commented Nov 15, 2012

@RKushnir we've just merged a change that will ignore the select values in 3a33572. If you think it can be improved, please feel free to open a new topic in the core mailing list. Thanks.

sgerrand pushed a commit to sgerrand/rails that referenced this pull request Nov 2, 2013

Refactor pluck with multiple columns
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment