Hello, 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 CASCADE" 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} (#{to_column})} 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 :-) Regards, Brian. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 support. However, I''m sure it would be interesting to see a plugin that extends the core migrations if you''re up for it. Steve --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brian, There is a foreign_key_migrations plugin for that and it works great for me. I am using it on postgres. http://www.redhillonrails.org/ -Wes James "Wes" Hays Great Basin Development P.O.Box 3503, Reno, Nevada 89505 Cell: (775) 745-3013 weshays-0t2l8SV1ciMAvxtiuMwx3w@public.gmane.org http://www.gbdev.com ----- Original Message ----- From: "candlerb" <b.candler-e+AXbWqSrlAAvxtiuMwx3w@public.gmane.org> To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Friday, March 23, 2007 1:24:53 PM (GMT-0800) America/Los_Angeles Subject: [Rails] ActiveRecord suggestion: column options Hello, 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 CASCADE" 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} (#{to_column})} 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 :-) Regards, Brian. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---