Module: ClosureTree::HierarchyMaintenance::ClassMethods

Defined in:
lib/closure_tree/hierarchy_maintenance.rb

Instance Method Summary collapse

Instance Method Details

#rebuild!Object

Rebuilds the hierarchy table based on the parent_id column in the database. Note that the hierarchy table will be truncated.


110
111
112
113
114
115
116
# File 'lib/closure_tree/hierarchy_maintenance.rb', line 110

def rebuild!
  _ct.with_advisory_lock do
    hierarchy_class.delete_all # not destroy_all -- we just want a simple truncate.
    roots.each { |n| n.send(:rebuild!) } # roots just uses the parent_id column, so this is safe.
  end
  nil
end