dependent: :destroy
在 ActiveRecord 模型中使用循环选项是否安全?
class Student < ActiveRecord::Base
has_one :user, dependent: :destroy
end
class User < ActiveRecord::Base
belongs_to :student, dependent: :destroy
end
如果我删除一个user
,它应该删除关联的student
. 反之亦然。
dependent: :destroy
在 ActiveRecord 模型中使用循环选项是否安全?
class Student < ActiveRecord::Base
has_one :user, dependent: :destroy
end
class User < ActiveRecord::Base
belongs_to :student, dependent: :destroy
end
如果我删除一个user
,它应该删除关联的student
. 反之亦然。