mirror of
https://github.com/github/rails.git
synced 2026-01-30 16:58:15 -05:00
Ruby 1.9 compat: check column type more carefully
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8439 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
*SVN*
|
||||
|
||||
* Ruby 1.9 compatibility. [Jeremy Kemper]
|
||||
|
||||
|
||||
*2.0.2* (December 16th, 2007)
|
||||
|
||||
* Ensure optimistic locking handles nil #lock_version values properly. Closes #10510 [rick]
|
||||
|
||||
@@ -417,7 +417,11 @@ module ActiveRecord
|
||||
# end
|
||||
def column(name, type, options = {})
|
||||
column = self[name] || ColumnDefinition.new(@base, name, type)
|
||||
column.limit = options[:limit] || native[type.to_sym][:limit] if options[:limit] or native[type.to_sym]
|
||||
if options[:limit]
|
||||
column.limit = options[:limit]
|
||||
elsif native[type.to_sym].is_a?(Hash)
|
||||
column.limit = native[type.to_sym][:limit]
|
||||
end
|
||||
column.precision = options[:precision]
|
||||
column.scale = options[:scale]
|
||||
column.default = options[:default]
|
||||
|
||||
@@ -255,26 +255,27 @@ module ActiveRecord
|
||||
def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
|
||||
if native = native_database_types[type]
|
||||
column_type_sql = native.is_a?(Hash) ? native[:name] : native
|
||||
|
||||
if type == :decimal # ignore limit, use precision and scale
|
||||
precision ||= native[:precision]
|
||||
scale ||= native[:scale]
|
||||
if precision
|
||||
|
||||
if precision ||= native[:precision]
|
||||
if scale
|
||||
column_type_sql << "(#{precision},#{scale})"
|
||||
else
|
||||
column_type_sql << "(#{precision})"
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale
|
||||
elsif scale
|
||||
raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified"
|
||||
end
|
||||
column_type_sql
|
||||
else
|
||||
limit ||= native[:limit]
|
||||
column_type_sql << "(#{limit})" if limit
|
||||
column_type_sql
|
||||
|
||||
elsif limit ||= native.is_a?(Hash) && native[:limit]
|
||||
column_type_sql << "(#{limit})"
|
||||
end
|
||||
|
||||
column_type_sql
|
||||
else
|
||||
column_type_sql = type
|
||||
type
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user