aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-05-16 14:16:57 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-05-16 14:16:57 -0700
commitd6e4c06a8a995a572237ebca96fa1d320e2418b3 (patch)
tree4258f4d43bc0b1b97447b73fe7e39262eb7d1da0
parent2a38fd58a91a300da5acfe917e82ac681dbd5b50 (diff)
downloadrails-d6e4c06a8a995a572237ebca96fa1d320e2418b3.tar.gz
rails-d6e4c06a8a995a572237ebca96fa1d320e2418b3.tar.bz2
rails-d6e4c06a8a995a572237ebca96fa1d320e2418b3.zip
assuming there is only one column, we can simplify the type cast loop
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb13
1 files changed, 6 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index aa9f7b71bf..31d99f0192 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -146,19 +146,18 @@ module ActiveRecord
result = klass.connection.select_all(select(column_name).arel, nil, bind_values)
- key = column = nil
- nullcast = Class.new { def type_cast(v); v; end }.new
+ key = result.columns.first
+ column = klass.column_types.fetch(key) {
+ result.column_types.fetch(key) {
+ Class.new { def type_cast(v); v; end }.new
+ }
+ }
result.map do |attributes|
raise ArgumentError, "Pluck expects to select just one attribute: #{attributes.inspect}" unless attributes.one?
value = klass.initialize_attributes(attributes).values.first
- key ||= attributes.keys.first
- column ||= klass.column_types.fetch(key) {
- result.column_types.fetch(key, nullcast)
- }
-
column.type_cast(value)
end
end