Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Merge pull request #8209 from senny/backport_8176"

This reverts commit 7240202, reversing
changes made to e4e2bcc.

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

Reason: This caused a regression since it changed the behavior in a
stable release.

Fixes #9777
  • Loading branch information...
commit 84c69a165380d4ae92322d4503a5b9a7201f6369 1 parent c910388
@rafaelfranca rafaelfranca authored
View
7 activerecord/CHANGELOG.md
@@ -1,5 +1,12 @@
## unreleased ##
+* Revert changes on `pluck` that was ignoring the select clause when the relation already
+ has one. This caused a regression since it changed the behavior in a stable release.
+
+ Fixes #9777.
+
+ *Rafael Mendonça França*
+
* Confirm a record has not already been destroyed before decrementing counter cache.
*Ben Tucker*
View
5 activerecord/lib/active_record/relation/calculations.rb
@@ -183,9 +183,8 @@ def pluck(column_name)
column_name = column_name.to_s
end
- relation = clone
- relation.select_values = [column_name]
- klass.connection.select_all(relation.arel).map! do |attributes|
+ column_name = column_name.to_s
+ klass.connection.select_all(select(column_name).arel).map! do |attributes|
klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes))
end
end
View
5 activerecord/test/cases/calculations_test.rb
@@ -493,9 +493,8 @@ def test_pluck_with_qualified_column_name
assert_equal [1,2,3,4], Topic.order(:id).pluck("topics.id")
end
- def test_pluck_replaces_select_clause
- taks_relation = Topic.select([:approved, :id]).order(:id)
- assert_equal [1,2,3,4], taks_relation.pluck(:id)
+ def test_pluck_does_not_replace_select_clause
+ taks_relation = Topic.select("approved, id, id AS foo_id").order(:foo_id)
assert_equal [false, true, true, true], taks_relation.pluck(:approved)
end
Please sign in to comment.
Something went wrong with that request. Please try again.