referential integrity in rails

≯℡__Kan透↙ 提交于 2019-12-04 14:10:42

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.

You can provide programmatic referential integrity by using

,:dependent => :restrict

on your has_one and has_many statements!

Blog describing this and how to check before error occurs

Relevant Active Record docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!