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

Use a hash to look up column definitions

This commit is contained in:
Aaron Patterson 2011-12-07 17:25:31 -08:00
parent 7e176a6d12
commit 76c29a64b9

View file

@ -66,6 +66,7 @@ module ActiveRecord
def initialize(base)
@columns = []
@columns_hash = {}
@base = base
end
@ -86,8 +87,7 @@ module ActiveRecord
# Returns a ColumnDefinition for the column with name +name+.
def [](name)
name = name.to_s
@columns.find { |column| column.name == name }
@columns_hash[name.to_s]
end
# Instantiates a new column for the table.
@ -283,6 +283,7 @@ module ActiveRecord
def new_column_definition(base, name, type)
definition = ColumnDefinition.new base, name, type
@columns << definition
@columns_hash[name] = definition
definition
end