Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

assuming there is only one column, we can simplify the type cast loop

  • Loading branch information...
commit d6e4c06a8a995a572237ebca96fa1d320e2418b3 1 parent 2a38fd5
@tenderlove tenderlove authored
Showing with 6 additions and 7 deletions.
  1. +6 −7 activerecord/lib/active_record/relation/calculations.rb
View
13 activerecord/lib/active_record/relation/calculations.rb
@@ -146,19 +146,18 @@ def pluck(column_name)
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
Please sign in to comment.
Something went wrong with that request. Please try again.