diff options
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 6bf3050af9..63365e501b 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -177,8 +177,23 @@ module ActiveRecord # Person.where(:confirmed => true).limit(5).pluck(:id) # def pluck(column_name) - klass.connection.select_all(select(column_name).arel).map! do |attributes| - klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes)) + key = column_name.to_s.split('.', 2).last + + if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s) + column_name = "#{table_name}.#{column_name}" + end + + result = klass.connection.select_all(select(column_name).arel) + types = result.column_types.merge klass.column_types + column = types[key] + + result.map do |attributes| + value = klass.initialize_attributes(attributes)[key] + if column + column.type_cast value + else + value + end end end |