aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/calculations.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-02-09 14:42:39 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-09 14:42:39 -0800
commite0eef111a31e1e442b60015b7c752cc1e2c21c57 (patch)
tree887fe52287d44a5c21b1d3cdcdd80d3c1bf0e680 /activerecord/lib/active_record/relation/calculations.rb
parente0cba3a0fab28f96dc9b5d3a714886583873a7d3 (diff)
downloadrails-e0eef111a31e1e442b60015b7c752cc1e2c21c57.tar.gz
rails-e0eef111a31e1e442b60015b7c752cc1e2c21c57.tar.bz2
rails-e0eef111a31e1e442b60015b7c752cc1e2c21c57.zip
typecast columns based on the returned types
Diffstat (limited to 'activerecord/lib/active_record/relation/calculations.rb')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 50239f7cb2..63365e501b 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -177,11 +177,23 @@ module ActiveRecord
# Person.where(:confirmed => true).limit(5).pluck(:id)
#
def pluck(column_name)
+ 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
- klass.connection.select_all(select(column_name).arel).map! do |attributes|
- klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes))
+
+ 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