84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
我现在有两个model,House和Company是多对一的关系,那么我想在删除Company的时候,如果有House引用就不能删除,否则可以直接删除Conmpany,这种关系需要怎么配置呢?
光阴似箭催人老,日月如移越少年。
试试这样写行不
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.
试试这样写行不
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.