Foreign keys

Hello,

I'm working on a legacy Rails project (they do exist already!) and I have some questions regarding foreign keys. Could someone point me to references on Rails and foreign keys? They don't seem to be used or encouraged, but I don't understand why. Can they be used and set up with migrations? (I know that can pose problems with the order of insertion but that can be solved in my case) How does Rails react when foreign keys give errors?

Thanks for your help, Bart

Many of us are using foreign key constraints in new apps as well.

You can execute the code to manually add/drop them in your migrations or use one of the fk migrations plugins.

When you violate a constraint, an ActiveRecord::StatementInvalid exception is raised.

jeremy

I use http://www.agilewebdevelopment.com/plugins/foreign_key_schema_dumper all the time. It allows you to write the fkeys right into your migrations.

Foreign keys can cause testing headaches, but googling ‘rails foreign key testing’ or something similar brings up a lot of good info.