Search code examples
ruby-on-railsforeign-keysreferential-integrity

referential integrity in Rails


Rails does not support referential integrity foreign keys. How do I manage this?

Ideally the app should not have to deal with this; the database should. Do plugins like Foreigner have shortcomings? How is this dealt with?


Solution

  • It's a design decision for Rails ActiveRecord.

    I consider stored procedures and constraints vile and reckless destroyers of coherence. No, Mr. Database, you can not have my business logic. Your procedural ambitions will bear no fruit and you'll have to pry that logic from my dead, cold object-oriented hands.

    Choose a single layer of cleverness - DHH

    So the answer is that referential integrity handled by the DB is not the Rails way at all.