根据条件销毁对象的所有依赖项的最佳/干燥方法是什么.?
例如:
class Worker < ActiveRecord::Base
has_many :jobs , :dependent => :destroy
has_many :coworkers , :dependent => :destroy
has_many :company_credit_cards, :dependent => :destroy
end
Run Code Online (Sandbox Code Playgroud)
条件将 在Destroy上:
if self.is_fired?
#Destroy dependants records
else
# Do not Destroy records
end
Run Code Online (Sandbox Code Playgroud)
有没有办法在依赖条件下使用Proc.我已经找到了单独销毁家属的方法,但这对于进一步的关联而言并非干燥和灵活,
注意:我已经编写了示例..而不是实际的逻辑
我想对ActiveRecord查询使用SQL子句"使用索引('index_name')",有没有人知道用Activerecord做这件事的好方法我想避免直接在查询中添加字符串.