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

Ticket #6883 (closed enhancement: worksforme)

Opened 3 years ago

Last modified 3 years ago

[PATCH] - when rails application over-rides nil overthows

Reported by: timcharper Assigned to: core
Priority: low Milestone: 1.x
Component: ActiveRecord Version:
Severity: normal Keywords:
Cc:

Description

I'm working on a rails application that changes the behavior of nils, which causes migrations to break. One could argue that you should change that behavior of ruby, of which I completely agree, but the consequences of this app would be devestating as there are no test cases.

Anyways, the primary_key database type is depending on the fact that type_to_sql will throw an error because when it looks up native database type key "int(11) DEFAULT NULL auto_increment PRIMARY KEY" - it doesn't exist. Obviously, it's expecting something like :string.

If no error is thrown, then nil is returned as the type, rather than the entire type "int(11) DEFAULT NULL auto_increment PRIMARY KEY" - which is what makes it work.

This patch makes the function not dependent on an error being thrown for the proper over-ride to be returned.

The better solution may be to change the native_database_type primary_key column, but I'm doubting that. A even better solution may be to just leave it alone. Anyways... if it adds value at all, here's the patch.

Index: C:/www/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb =================================================================== --- C:/www/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (revision 5774) +++ C:/www/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb (working copy) @@ -254,6 +254,7 @@

def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:

native = native_database_types[type]

+ return type if ! native

column_type_sql = native[:name] if type == :decimal # ignore limit, use precison and scale

precision = native[:precision]

Change History

09/04/07 12:37:38 changed by lifofifo

  • status changed from new to closed.
  • resolution set to worksforme.

Please reopen if this is still a problem on latest edge.