def apply_orphan_strategy
unless ancestry_callbacks_disabled?
unless new_record?
if self.base_class.orphan_strategy == :rootify
descendants.each do |descendant|
descendant.without_ancestry_callbacks do
descendant.update_attribute descendant.class.ancestry_column, (if descendant.ancestry == child_ancestry then nil else descendant.ancestry.gsub(/^#{child_ancestry}\//, '') end)
end
end
elsif self.base_class.orphan_strategy == :destroy
descendants.all.each do |descendant|
descendant.without_ancestry_callbacks do
descendant.destroy
end
end
elsif self.base_class.orphan_strategy == :restrict
raise Ancestry::AncestryException.new('Cannot delete record because it has descendants.') unless is_childless?
end
end
end
end