collectiveidea/awesome_nested_set — Issue #116: Model.rebuild! does not rebuild depth
Author: spalladino
Created: 2012-01-27 20:53:26+00:00
State: open

When executing rebuild! to convert an existing tree (from a previous version that did not support depth), the depth field is not completed automatically.

valid? should also check that this field is correct if it is present.

We are currently using the following monkeypatch for solving the issue.

```ruby
def self.rebuild!
items = self.where(:parent_id => nil)
level = 0
while items.any?
items.update_all :depth => level
items = self.where(:parent_id => items.map(&:id))
level += 1
end
super
end
```