AR::Relation#pluck: improve to work with joins #4942

Merged
merged 1 commit into from Feb 8, 2012

Conversation

Projects
None yet
6 participants
Contributor

bogdan commented Feb 8, 2012

When Relation has some joined table, columns like id will become ambiguous.
This patch automatically plucks column from main table if possible, like:

User.joins(:projects).pluck(:id) # select users.id from users join projects on ...

josevalim added a commit that referenced this pull request Feb 8, 2012

Merge pull request #4942 from bogdan/pluck_joins
AR::Relation#pluck: improve to work with joins

@josevalim josevalim merged commit e7627d2 into rails:master Feb 8, 2012

Contributor

bogdan commented Feb 9, 2012

One question: what about moving this into AR::Relation#select?
So that:

User.joins(:projects).select(:id) # select users.id from users join projects on
Contributor

le0pard commented Jun 5, 2012

I cannot find this commit in the branch 3.2.5, only in master. In which version of rails, this method will be fixed?

mhuggins commented Dec 2, 2012

This seems like something that should be backported to 3.2, but I'm only seeing it in master branch. Any chance we can get it included in 3.2.x?

josevalim added a commit that referenced this pull request Dec 4, 2012

Merge pull request #4942 from bogdan/pluck_joins
AR::Relation#pluck: improve to work with joins

Conflicts:
	activerecord/lib/active_record/relation/calculations.rb
	activerecord/test/cases/calculations_test.rb

@mhuggins there you go a878126.

It does not include in 3.2.10 nor 3.2.11, but 3.2.12(Unreleased)

https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md

Yup, we have to wait for the next 3.2.x release, or bundle from github, 3-2-stable branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment