ruby - 关于rails model的关系维护
大家讲道理
大家讲道理 2017-04-21 11:15:58
0
1
617

我现在有两个model,House和Company是多对一的关系,那么我想在删除Company的时候,如果有House引用就不能删除,否则可以直接删除Conmpany,这种关系需要怎么配置呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
Peter_Zhu

试试这样写行不

 has_many :houses, dependent: :restrict

http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many

:restrict this object raises an ActiveRecord::DeleteRestrictionError exception and cannot be deleted if it has any associated objects.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!