aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorKevin Deisz <kevin.deisz@gmail.com>2015-05-29 09:41:03 -0400
committerKevin Deisz <kevin.deisz@gmail.com>2015-05-29 10:32:32 -0400
commit777fa257aaa962bf67f6e5522efaa420ea7dc88b (patch)
tree088161d48ab11cca58e09cb3d49c73a3f76db613 /activerecord/lib/active_record/relation/calculations.rb
parent343dad9617e7448bf8effc7c70ae13bede38fd32 (diff)
downloadrails-777fa257aaa962bf67f6e5522efaa420ea7dc88b.tar.gz
rails-777fa257aaa962bf67f6e5522efaa420ea7dc88b.tar.bz2
rails-777fa257aaa962bf67f6e5522efaa420ea7dc88b.zip
Allow Enumerable#pluck to take a splat.
This allows easier integration with ActiveRecord, such that AR#pluck will now use Enumerable#pluck if the relation is loaded, without needing to hit the database.
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 402b317d9c..7a28a98721 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -161,6 +161,10 @@ module ActiveRecord
end
end
+ if loaded? && (column_names - @klass.column_names).empty?
+ return @records.pluck(*column_names)
+ end
+
if has_include?(column_names.first)
construct_relation_for_association_calculations.pluck(*column_names)
else