aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md7
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb5
-rw-r--r--activerecord/test/cases/calculations_test.rb5
3 files changed, 11 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index c372f94729..117e527133 100644
--- a/activerecord/CHANGELOG.md
+++ b/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*
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 1f9dbdc3d4..71d33fcd4e 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -183,9 +183,8 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index a1dc1de38d..b9050c750f 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -493,9 +493,8 @@ class CalculationsTest < ActiveRecord::TestCase
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