I followed the Installation instructions from the README.md but was confused by the last step. That says
- If you're migrating from another system where your model already has a
parent_id column, run Tag.rebuild! and your tag_hierarchies table will be truncated and rebuilt.
If you're starting from scratch you don't need to call rebuild!.
At this point, my model has a parent_id column but I am not migrating from another system. I am simply adding hierarchy to an existing model, let's call it Tag, and the database has a small pile of instances. The migrations added the parent_id column to that model and closure_tree:migration generator added an empty tag_hierarchies table to the database. All Tag instances have their parent_id attribute set to nil at this point.
If I then execute something like Tag.first.ancestry_path in the Rails console, I get an empty array. I had expected to get an array with Tag.first.name.
Running Tag.rebuild! (before saving any parent_id values to the database) seems to fix this but I am not sure if that is what I am supposed to be doing given the documentation. If it is, is doing this backfilling in a migration the recommended way of doing so? How would I revert that?
I followed the Installation instructions from the README.md but was confused by the last step. That says
At this point, my model has a
parent_idcolumn but I am not migrating from another system. I am simply adding hierarchy to an existing model, let's call itTag, and the database has a small pile of instances. The migrations added theparent_idcolumn to that model andclosure_tree:migrationgenerator added an emptytag_hierarchiestable to the database. AllTaginstances have theirparent_idattribute set tonilat this point.If I then execute something like
Tag.first.ancestry_pathin the Rails console, I get an empty array. I had expected to get an array withTag.first.name.Running
Tag.rebuild!(before saving anyparent_idvalues to the database) seems to fix this but I am not sure if that is what I am supposed to be doing given the documentation. If it is, is doing this backfilling in a migration the recommended way of doing so? How would I revert that?