Module: Redmine::NestedSet::IssueNestedSet::ClassMethods

Defined in:
lib/redmine/nested_set/issue_nested_set.rb

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

#rebuild_tree!Object



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/redmine/nested_set/issue_nested_set.rb', line 174

def rebuild_tree!
  transaction do
    reorder(:id).lock.ids
    update_all(:root_id => nil, :lft => nil, :rgt => nil)
    where(:parent_id => nil).update_all(["root_id = id, lft = ?, rgt = ?", 1, 2])
    roots_with_children = joins("JOIN #{table_name} parent ON parent.id = #{table_name}.parent_id AND parent.id = parent.root_id").uniq.pluck("parent.id")
    roots_with_children.each do |root_id|
      rebuild_nodes(root_id)
    end
  end
end