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

schema cache already has the columns as a hash, so use that

上级 c99e34e9
......@@ -287,7 +287,7 @@ def reset_sequence!(table, column, sequence = nil)
# Inserts the given fixture into the table. Overridden in adapters that require
# something beyond a simple insert (eg. Oracle).
def insert_fixture(fixture, table_name)
columns = Hash[schema_cache.columns(table_name).map { |c| [c.name, c] }]
columns = schema_cache.columns_hash(table_name)
key_list = []
value_list = fixture.map do |name, value|
......
module ActiveRecord
module ConnectionAdapters
class SchemaCache
attr_reader :columns_hash, :primary_keys, :tables, :version
attr_reader :primary_keys, :tables, :version
attr_accessor :connection
def initialize(conn)
......@@ -39,6 +39,16 @@ def columns(table = nil)
end
end
# Get the columns for a table as a hash, key is the column name
# value is the column object.
def columns_hash(table = nil)
if table
@columns_hash[table]
else
@columns_hash
end
end
# Clears out internal caches
def clear!
@columns.clear
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册