Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8439

Show
Ignore:
Timestamp:
12/19/07 09:31:57 (1 year ago)
Author:
bitsweat
Message:

Ruby 1.9 compat: check column type more carefully

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r8419 r8439  
     1*SVN* 
     2 
     3* Ruby 1.9 compatibility.  [Jeremy Kemper] 
     4 
     5 
    16*2.0.2* (December 16th, 2007) 
    27 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

    r8304 r8439  
    418418      def column(name, type, options = {}) 
    419419        column = self[name] || ColumnDefinition.new(@base, name, type) 
    420         column.limit = options[:limit] || native[type.to_sym][:limit] if options[:limit] or native[type.to_sym] 
     420        if options[:limit] 
     421          column.limit = options[:limit] 
     422        elsif native[type.to_sym].is_a?(Hash) 
     423          column.limit = native[type.to_sym][:limit] 
     424        end 
    421425        column.precision = options[:precision] 
    422426        column.scale = options[:scale] 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

    r8113 r8439  
    256256        if native = native_database_types[type] 
    257257          column_type_sql = native.is_a?(Hash) ? native[:name] : native 
     258 
    258259          if type == :decimal # ignore limit, use precision and scale 
    259             precision ||= native[:precision] 
    260260            scale ||= native[:scale] 
    261             if precision 
     261 
     262            if precision ||= native[:precision] 
    262263              if scale 
    263264                column_type_sql << "(#{precision},#{scale})" 
     
    265266                column_type_sql << "(#{precision})" 
    266267              end 
    267             els
    268               raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale 
     268            elsif scal
     269              raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" 
    269270            end 
    270             column_type_sql 
    271           else 
    272             limit ||= native[:limit] 
    273             column_type_sql << "(#{limit})" if limit 
    274             column_type_sql 
     271 
     272          elsif limit ||= native.is_a?(Hash) && native[:limit] 
     273            column_type_sql << "(#{limit})" 
    275274          end 
     275 
     276          column_type_sql 
    276277        else 
    277           column_type_sql = type 
     278          type 
    278279        end 
    279280      end