I've been trying to find a good way of doing this, either on the client side in Javascript or at the last minute within the server. This is a Rails application but it is a pretty generic question. I have a model that is hierarchical, and is currently stored in a nested set model. The model then has:
parent_id, lft, and rgt
I would like to pull out all of the models in one select statement from the database, therefore giving me a flat list of models, and then sort them on the fly into a tree hierarchy. I have not found a clean way to do this that would not require recursion. I'm sure there is a nice algorithm out there for this. Thanks.