> Getting off the topic of CF (and esp. of FuseBox), the Nested Trees model
> seems to offer huge benefits in extracting meaningful hierarchical data,
but
> at a large cost when INSERTing, DELETEing and otherwise re-arranging the
> tree.
>
> Have you (or any of us) any real-world tales about the pros and cons of
> these trade-offs?
this is a great example where a explicit and intentional non-normal form of
a database table may come in handy.
The big *if* is whether the table in question suffers from constant updates
and the like. If not, or if it does but they all happen at once (example:
suppose the Tree in question is one of categorys---your users never change
these but you the admin may well do so--but when you do it is rare and you
do all the changes all at once). In this case it is not a heretical idea to
create another table with a PK the same as the Categorys table and in it put
several pieces of info that is of use when re-constructing trees--this
parallel 1-to-1 table is updated any time a change is made to the main
Categorys table. Then you can extract this relational-in-human-space data
fairly easily. Examples to store might be: Node (how deep down the tree),
Position from Top (how far down the tree the item is if a human is looking
at the tree, Ancestors (even go so far as to make the a text fields with the
ancestral parents separated by commas), and DirectChildren. With just these
4 fields you can quickly reconstruct all sorts of variations on the Tree
data at any time.
The Node and Position from Top are particularly useful (since the other two
could be derived from them if need be) and gives you an easy way to know
exactly how deep one has to go. In particular there are two uses for these:
(1) given a certain item in the Tree give all the descendants from that
point forward (here loop forward from Position from Top until you get a Node
equal to or less than the Item's Node) and (2) give direct line ancestors
(useful when you need to re-construct the tree to the given Item--even when
you dont care about the ancestor items per se but need to conceptualize the
path down the Tree for the user.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists