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?
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?
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.