Skip to content

Converting Acts_As_Tree to Awesome_Nested_Set

kucaahbe edited this page Sep 12, 2010 · 2 revisions

To convert a table that is established as a tree using acts_as_tree to an awesome_nested_set is a relatively simple process.

  1. Install the awesome_nested_set plugin.
  2. Generate, edit and run a migration to add the columns `lft` and `rgt` to your Model. The column `parent_id` should already exist and be populated with your tree relationships.
  3. if you used acts_as_ordered_tree plugin you need to change your parent_id column “0” values to NULL in the database
  4. In either the console, or a controller action, simply execute YourModel.rebuild!

This will send the plugin through your table and populate the `lft` and `rgt` columns with the appropriate values.

Thanks for writing an excellent plugin and providing this simple feature. I hope these instructions will make someones transfer a lot easier!