Storing documents in a parent/child hierarchy is one of the things Notes does with ease. This makes it really simple to create databases such as discussion forums where this type of document relationship lends itself perfectly. It's not quite so simple however when the relationship between document becomes any more complicated than one parent to many children.
The simple one-to-many scenario didn't fit my requirements recently and so I had to re-think the way Notes documents in a certain database were structured. What I needed was a way for a child document to have many parents and many children, each of which could, in turn, have many parents. The solution I came up with was surprisingly simple. Portable too. Hence I thought it worth sharing.
The scenario I encountered involved a database which stores "team" documents. Each Team document stores a list of its members along with a series of child documents which record upcoming meetings, discussions etc which relate to that Team.
The Teams are arranged in a hierarchy according to who they each report to. Each team (akin to a department, if you will, such as HR or Finance) can report to more than one parent team and the reporting structure can be any number of levels deep.
After lots of careful thought I managed to solve the (seemingly complex) problem very simply with the addition of one field to the Team form. The field is called "ChildOf" and stores a list of the document IDs of that Team's parent Teams. Any Team with a blank ChildOf field is assumed to be the top-tier team that reports to no body.
The only other design element I needed to add was a view categorised by the ChildOf field which let you easily find the sub-Teams of any one team. The rest of what I added was simple code to recursively display the whole hierarchy in a "view" style. The only other code needed was the logic to check that silly things like adding a team as a child of itself never happened. All in all it was quite simple to do and amazingly flexible for such a simple solution. The same solution could easily be applied to any number of scenarios -- even if it's a drop-down menu builder.
Later on this week I'll have a demo to show you and talk a bit more about the code involved. For now I just wanted to pass the idea by you all to see what you thought. Does it sound useful or not?