diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-01 17:54:30 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-01 17:54:40 -0700 |
commit | 6518f12b73546ee566ecef76f8d13da6f16272a0 (patch) | |
tree | 771aa892eb2902941297ac01bae25024adefcd86 /activerecord/lib/active_record/relation/calculations.rb | |
parent | 1144d5e4a1bab6520b0ff6ffa26e04aeabfb3bc7 (diff) | |
download | rails-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.rb | 18 |
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) { |