My application manages business rules, and nested tasks. During a normal creation process, some attributes are initialised in a call-back, such as before_create :set_hierarchy
, for each object (rule & tasks).
For managing versions of a business rule, I dup
it, including nested tasks. In this case, the before_create call-back must not be executed neither for the business rule, nor for the tasks.
Disabling a call-back off BusinessRule class is a known operation, but how to disable the call-back off the nested class?
My code is:
BusinessRule.without_callback(:create, :before, :set_hierarchy) do
@business_rule_version = @business_rule.dup
@business_rule.tasks.each do |task| # Duplicate associated tasks too
dup_task = task.dup
dup_task.business_rule_id = @business_rule_version.id
dup_task.save
end
end
This works fine for the business rule, but how can I specify this without_callback clause for the nested tasks? I tried the deep_clone gem, which leaves me with the same question ...
Thanks a lot for your help!