TreeManager CFC Released

I put together this component a while back, intending to eventually
release it, and it's now time.  Basically it manages a tree of
records in a databas table using the nested set model.  It acts
independantly of your existing persistance operations, and only
requires the addition of two fields to your table for it's use. 
You continue to manage your rows as you do right now, completely
ignoring the two extra fields, and then when you need to do tree-based
operations, you call the tree manager, and it takes care of all the

in the zip (link below) is a very simple
application that creates a table, populates it with a bunch of data,
and then uses the tree manager to create a hierarchy out of the
records.  It doesn't really illustrate any of the action methods
in the component, but I wanted to get it out while I was on a role, and
didn't figure I'd ever finish if I tried to write a complete
example.  However, complete documentation is included, and the CFC
itself is fully commented.

So enough boring chit-chat, here's the code:

only tested it on CFMX 6.1 and MySQL 4.1.  I know it won't work on
database other than MySQL 4.1 and higher (because there are a few LIMIT
clauses), but porting it to other DBs should be relatively
trivial.  I don't have access to anything else, so I can't do it,
but if you feel so inclined, please send me a patch so that I can
integrate it into the distributed version.  And you needn't
understand the nested set model to hack the SQL, most of the queries
are pretty simple, it's just the amalgamation of operations that does
the magic.

There is no license, so do what you will, though I'd
appreciate credit of some sort if that's appropriate for your

6 responses to “TreeManager CFC Released”

  1. Brian Rinaldi

    Barney, I have ported your treemanager to MSSQL. It was pretty much just changing the "limit" keywords – only sortChildren presented a challenge as it used an offset in the limit which isn't available in t-sql. The only caveat is that I changed it to work with SQL unique identifier, but that is essentially a find/replace. I am happy to send it to you if you would like.

  2. Arturo Batanero

    Looks extremely interesting, but the download link is broken. Could upload the file again?

  3. Dan Sorensen


    I'm interested in seeing your treemanager.cfc as soon as you can get it back online as well. I had been working on my own version before I heard that you had already done something along these lines.

    Specifically, I'm looking for an elegant way to reorder children under a specified node.

    Can I assume that the 'two extra fields' you require are the classic "left_side", "right_side" discussed in Nested Set Model articles or do you need something else?


  4. Aaron Z. Ward

    Any idea when you might be able to re-up the file ? I'd be interested in looking at the implementation. It's been years since I've had fingers in real data structures…looks like some fun stuff.

    btw: I can host the file if needed.

  5. Janet


    If you're still looking for TreeManager I think there's a download link in this article. (Though I'm not sure what version it is)