1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

This commit is contained in:
Aaron Patterson 2012-05-16 14:16:57 -07:00
parent 2a38fd58a9
commit d6e4c06a8a

View file

@ -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