提交 d6e4c06a 编写于 作者: A Aaron Patterson

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

上级 2a38fd58
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册