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.



78
79
80
81
82
83
84
# File 'lib/closure_tree/hierarchy_maintenance.rb', line 78

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