automatically add the column definition to the columns list if creating a new one

This commit is contained in:
Aaron Patterson 2011-12-07 16:01:53 -08:00
parent 1fc47a1a84
commit 483a3cf287

@ -225,17 +225,20 @@ def [](name)
# t.references :taggable, :polymorphic => { :default => 'Photo' }
# end
def column(name, type, options = {})
column = self[name] || ColumnDefinition.new(@base, name.to_s, type)
if options[:limit]
column.limit = options[:limit]
elsif native[type.to_sym].is_a?(Hash)
column.limit = native[type.to_sym][:limit]
name = name.to_s
type = type.to_sym
column = self[name] || new_column_definition(@base, name, type)
limit = options.fetch(:limit) do
native[type][:limit] if native[type].is_a?(Hash)
end
column.limit = limit
column.precision = options[:precision]
column.scale = options[:scale]
column.default = options[:default]
column.null = options[:null]
@columns << column unless @columns.include? column
column.scale = options[:scale]
column.default = options[:default]
column.null = options[:null]
self
end
@ -276,9 +279,15 @@ def to_sql
end
private
def native
@base.native_database_types
end
def new_column_definition(base, name, type)
definition = ColumnDefinition.new base, name, type
@columns << definition
definition
end
def native
@base.native_database_types
end
end
# Represents an SQL table in an abstract way for updating a table.