diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-05-16 11:17:04 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-05-16 11:17:04 -0700 |
commit | aa964204b867b3e69c1e68fbaec101ce9cbaa0ef (patch) | |
tree | 9d76a484b2446a8af531ef40b0f460eb10dd6d52 /activerecord/lib/active_record/relation/calculations.rb | |
parent | e29626901ad82bafeb7ade13c3681aa777d7fe2a (diff) | |
parent | c90f16da626a7edac45f7027b127ad874619455a (diff) | |
download | rails-aa964204b867b3e69c1e68fbaec101ce9cbaa0ef.tar.gz rails-aa964204b867b3e69c1e68fbaec101ce9cbaa0ef.tar.bz2 rails-aa964204b867b3e69c1e68fbaec101ce9cbaa0ef.zip |
Merge pull request #6336 from erichmenge/patch-pluck-fragment
Fixes issue where SQL fragments prevented type casting based on column
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index aa2f325f74..862009b1ba 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -147,17 +147,12 @@ module ActiveRecord end result = klass.connection.select_all(select(column_name).arel, nil, bind_values) - types = result.column_types.merge klass.column_types - column = types[key] + column = klass.column_types[key] || result.column_types.values.first result.map do |attributes| raise ArgumentError, "Pluck expects to select just one attribute: #{attributes.inspect}" unless attributes.one? - value = klass.initialize_attributes(attributes).first[1] - if column - column.type_cast value - else - value - end + value = klass.initialize_attributes(attributes).values.first + column ? column.type_cast(value) : value end end |