aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-01 17:54:30 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-01 17:54:40 -0700
commit6518f12b73546ee566ecef76f8d13da6f16272a0 (patch)
tree771aa892eb2902941297ac01bae25024adefcd86 /activerecord/lib/active_record/relation/calculations.rb
parent1144d5e4a1bab6520b0ff6ffa26e04aeabfb3bc7 (diff)
downloadrails-6518f12b73546ee566ecef76f8d13da6f16272a0.tar.gz
rails-6518f12b73546ee566ecef76f8d13da6f16272a0.tar.bz2
rails-6518f12b73546ee566ecef76f8d13da6f16272a0.zip
build an AST rather than slapping strings together
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb18
1 files changed, 7 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 48a96fec64..7d745c757b 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -137,24 +137,20 @@ module ActiveRecord
#
def pluck(*column_names)
column_names.map! do |column_name|
- if column_name.is_a?(Symbol)
- if attribute_alias?(column_name)
- column_name = attribute_alias(column_name).to_sym
- end
-
- if self.columns_hash.key?(column_name.to_s)
- column_name = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
- end
+ if column_name.is_a?(Symbol) && attribute_alias?(column_name)
+ attribute_alias(column_name).to_sym
+ else
+ column_name
end
-
- column_name
end
if has_include?(column_names.first)
construct_relation_for_association_calculations.pluck(*column_names)
else
relation = spawn
- relation.select_values = column_names
+ relation.select_values = column_names.map { |cn|
+ columns_hash.key?(cn.to_s) ? arel_table[cn] : cn
+ }
result = klass.connection.select_all(relation.arel, nil, bind_values)
columns = result.columns.map do |key|
klass.column_types.fetch(key) {