我现在有两个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.