ActiveRecord suggestion: column options


I'm using rails-1.2.2 with ActiveRecord-1.15.2. I have a small feature
request for ActiveRecord.

When creating a table, AR lets you add options to the whole table, but
not for individual columns. I would like to be able to write:

  t. column foo_id, :integer,
       :options => "CONSTRAINT fk_foo_id REFERENCES a(id) ON DELETE

Why? Because this syntax is accepted by both Oracle and Sqlite3
(although Sqlite3 silently ignores it), so the migration is portable.

However, if create the table first, and then do

    execute %{alter table #{from_table}
              add constraint #{constraint_name}
              foreign key (#{from_column}) references #{to_table}

Sqlite3 rejects this with an exception. Sure I can rescue this:

  rescue ActiveRecord::StatementInvalid => e
    raise unless /SQLite/ =~ e

It's just a bit ugly. But this is a minor point. AR rocks :slight_smile:



Sounds interesting but is perhaps a fringe requirement. It's quite
common to enforce constraints in the application in rails rather than
the database. It also seems at first look to have limited database

However, I'm sure it would be interesting to see a plugin that extends
the core migrations if you're up for it.



There is a foreign_key_migrations plugin for that and it works great for me. I am using it on postgres.


James "Wes" Hays
Great Basin Development
P.O.Box 3503, Reno, Nevada 89505
Cell: (775) 745-3013