根据条件销毁对象的所有依赖项的最佳/干燥方式是什么。?
前任:
class Worker < ActiveRecord::Base
has_many :jobs , :dependent => :destroy
has_many :coworkers , :dependent => :destroy
has_many :company_credit_cards, :dependent => :destroy
end
条件将是 销毁:
if self.is_fired?
#Destroy dependants records
else
# Do not Destroy records
end
有没有办法在 :dependent 条件下使用 Proc。我已经找到了单独销毁家属的方法,但这对于进一步的关联并不干燥且灵活,
注意:我已经编造了这个例子..不是一个实际的逻辑