Rails 2.1 broke my mysql foreign keys!

June 24th, 2008 by John Trupiano

Rails 2.1 introduced in the MySQL Adapter “smart integer columns.” The idea was to use the :limit option to determine whether a smallint, int, or bigint should be used. This is something that the Postgres adapter had already previously implemented. The relevant code in activerecord/lib/active_record/connection_adapters/mysql_adapter.rb is:

  # Maps logical Rails types to MySQL-specific data types.
  def type_to_sql(type, limit = nil, precision = nil, scale = nil)
    return super unless type.to_s == 'integer'
 
    case limit
    when 0..3
      "smallint(#{limit})"
    when 4..8
      "int(#{limit})"
    when 9..20
      "bigint(#{limit})"
    else
      'int(11)'
    end
  end

Mirko Froehlich suggests monkey patching this function. Timothy Jones blogged about it.

To monkey-patch this, just drop a file (fix_mysql_adapter.rb) into your initializers/ directory, as such:

Read the rest of this entry »

Don’t Abuse the Session

June 23rd, 2008 by John Trupiano

Google AJAX Libraries on Rails

June 20th, 2008 by Nick Gauthier

Automating Flex Compilation Using ANT

June 15th, 2008 by Greg Jastrab

Ruby on Rails Polymorphic Association Benchmarks

June 13th, 2008 by Nick Gauthier

Multithreading in Ruby on Rails

June 11th, 2008 by Nick Gauthier

Subversion Timestamps + Capistrano finalize_update

June 7th, 2008 by John Trupiano

Deploying Rails Apps with Capistrano without root or sudo Privileges

June 6th, 2008 by John Trupiano

map.resources and custom nested routes

June 5th, 2008 by Scott Davis

Sexier Migrations in Rails 2.1

June 5th, 2008 by Glenn Gentzke