aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-07 16:01:53 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-07 16:01:53 -0800
commit483a3cf2872a6a5d544f2c15cb60d0bf2bce036a (patch)
tree9c88cad89cace87a3f06691dc6043ab6d8bcc3f8 /activerecord
parent1fc47a1a8438905b7097ce14a538d3209aa4a25c (diff)
downloadrails-483a3cf2872a6a5d544f2c15cb60d0bf2bce036a.tar.gz
rails-483a3cf2872a6a5d544f2c15cb60d0bf2bce036a.tar.bz2
rails-483a3cf2872a6a5d544f2c15cb60d0bf2bce036a.zip
automatically add the column definition to the columns list if creating a new one
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb33
1 files changed, 21 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
index eb67e96705..ce7a5d4156 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -225,17 +225,20 @@ module ActiveRecord
# 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 @@ module ActiveRecord
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.