提交 6cd8e3f5 编写于 作者: A Aaron Patterson

make the identity type a singleton to save on object creation

上级 b7aba569
......@@ -154,9 +154,7 @@ def pluck(*column_names)
result = klass.connection.select_all(relation.arel, nil, bind_values)
columns = result.columns.map do |key|
klass.column_types.fetch(key) {
result.column_types.fetch(key) {
Class.new { def type_cast(v); v; end }.new
}
result.column_types.fetch(key) { result.identity_type }
}
end
......
......@@ -8,6 +8,8 @@ module ActiveRecord
class Result
include Enumerable
IDENTITY_TYPE = Class.new { def type_cast(v); v; end }.new # :nodoc:
attr_reader :columns, :rows, :column_types
def initialize(columns, rows, column_types = {})
......@@ -17,6 +19,10 @@ def initialize(columns, rows, column_types = {})
@column_types = column_types
end
def identity_type # :nodoc:
IDENTITY_TYPE
end
def each
if block_given?
hash_rows.each { |row| yield row }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册