Permalink
Browse files

Wrap rebuild_depth_cache! in a transaction

  • Loading branch information...
1 parent 1368853 commit b8a98e5d1dbf30339ac4c83d0b6372babf19e4dd @mjc mjc committed Dec 18, 2013
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/ancestry/class_methods.rb
@@ -185,9 +185,11 @@ def build_ancestry_from_parent_ids! parent_id = nil, ancestry = nil
def rebuild_depth_cache!
raise Ancestry::AncestryException.new("Cannot rebuild depth cache for model without depth caching.") unless respond_to? :depth_cache_column
- self.ancestry_base_class.unscoped do
- self.ancestry_base_class.find_each do |node|
- node.update_attribute depth_cache_column, node.depth
+ self.ancestry_base_class.transaction do
+ self.ancestry_base_class.unscoped do
+ self.ancestry_base_class.find_each do |node|
+ node.update_attribute depth_cache_column, node.depth
+ end
end
end
end

0 comments on commit b8a98e5

Please sign in to comment.