I understand. 2 possible aproximation without thinking too much.
Maybe you can have a field called “parent”. If you pesent me, then my parent are your ID (1 for example), those I present parent fields is equal to my ID, and so on.
Then, when you show data, you have to do research on table all records where parent is the user ID, and collect them on a array for example, then other filter with “childs” ID, and again adding this IDs to “our” array.
Then, you can use a “SELECT … IN” against the array to show all records with parent=all parentcodes in array.
Other aprox more easy, is create your own field simulating a tree.
your ID is 1 then. “TreeField” for your agents, are 1-1, 1-2, 1-3…agents for your first agent will be 1-1-1, 1-1-2 and so on.
Then, you just need to filter until the level you need. Ex: Filter under “TreeField” = “1-%” just your “child” agents, and child agents of your child agents (OMG) will match this key. because I, with ID=2, have a structure like 2-1 2-2 2-1-1 and so on… and your first level child for your first child, must match something like 2-1-%, and your contracts can’t be showed to him.
I hope I explained correctly.
- I need to take a child, errr a drink