What’s brewing over at ListFinity, home of infinite lists?
Well, supposedly right now I’m working out various means of constructing and manipulating “infinitely nestable” lists, as in an object hierarchy (aka tree view) of arbitrary depth.
That’s all well and good, but not as straightforward to code as the display of a single unordered list. I figured that such a hierarchy would be a good candidate for recursion, and in this case that didn’t sound like too big a chore to write… except when I started to imagine that each loop back to the recursive method would want to pass on the list data for the next loop to walk through another level, etc. This triggered a flash of nightmares where a sufficiently large or deep list (nevermind one mangled to include circular references) spurs the recursion on to eat memory like a mosquito with its proboscis stuck in the jugular.
Then I started reading about acts_as_tree. Hey, hierarchy wiring ready to go! And I had already named a column parent_id in expectation of having to manage a hierarchy all on my own. Now it’s possible to take a plain old table, with a parent_id column, and quickly apply a hierarchy skeleton.
There’s also acts_as_nested_set, which sounds cool but seems to have some issues. Plus better nested set but at this stage that may actually be a bit more than I need. Retrieving an entire set of descendants in one query does sound attractive though.
Back to our simple acts_as_tree model, someone has already put some effort into addressing how to display the tree. I’ll start there and see how it works out.