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:
parent
2a38fd58a9
commit
d6e4c06a8a
1 changed files with 6 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue