Forum Discussion

Re: Recommendation on best way to create hierarchy between client contacts

Ivan,

Thanks for the clarification. I'm going to assume your client list table is called "Clients."

I think an additional table to track hierarchies is still the direction you want to go (maybe a separate table for each hierarchy step if it's going to remain fairly static.) If you relate Clients to Clients, you'll have to add a new table relationship for each additional field (not fun.) Having Parent records automatically know their Children or Grandchildren could get tricky, but once you figure that out, it will be simpler to manage.

From there, you can set up report links to display the information your form. Lookup fields counting the total # of Child records for each hierarchy step can then feed form rules to display different aspects of the Client form.


------------------------------
Evan Westbrook
PRIME Developer
Harder Mechanical Contractors Inc.
Portland OR
------------------------------

4 Replies

  • IvanWeiss's avatar
    IvanWeiss
    Qrew Captain
    Evan, so I did not quite follow you.  The table is called Contacts.

    I was assuming I could self relate it and just do it that way.
    But you are saying do a separate table and name it lets say Contact Hierarchy.  I am thinking it should relate to the Contacts table twice
    The first one being the Employee and the second one being the Manager?  Is that correct?  And use that to report out the work since it is linking people?  I guess what I was somewhat confused by is each Manager can have several Employees reporting to them.

    ------------------------------
    Ivan Weiss
    ------------------------------
    • EvanWestbrook's avatar
      EvanWestbrook
      Qrew Cadet
      Ivan,

      I think we're on the same page with how Contact Hierarchy would work. I did want to touch on some items behind the recommendation for a second table, as I think this one could go either way.

      Item 1: Data Structure Best Practices
      A good goal for many databases is 3rd Normal Form. Essentially, this just means that the tables in a database are set up such that a piece of data only exists in one place.

      I should note that this is a "Recommended Best" practice and not "The Only" practice. Design goals should be balanced with business needs for the database. Examples where a database might not be fully "normalized" are typically related to performance (reporting databases, data warehouses, query response times, end user workflows, etc.) 

      QuickBase University has some great notes on this if you'd like more information.

      Item 2: This use case could go either way
      A second table vs. relating a table to itself is sometimes a "to-may-to" "to-mah-to" situation. In the below image, Options 1 and 2 can more or less do the same thing.

      We even have some self-related tables like Option 2 in some of our production apps.

      Item 3:  Option 1 vs. Option 2
      When designing databases and writing code, efficiency, performance, and simplicity are important. Readability, maintainability, and debugability are also important.  In my experience, Option 2 relationships in our apps have been difficult to debug and difficult to explain when on boarding new team members. It's less clear what the table relationship does at a quick glace.

      Option 1 is also closer to 3rd Normal Form, and it gives us a lot of potential benefits: The hierarchy relationships between Contacts exist in a single location. It's more clear to any app users how Contacts are related to each other. It sets the foundation for future business needs (i.e. allowing other tables to use this contact hierarchy.) Updating future Contact Hierarchies (i.e. Bob gets promoted from DM to RVP) is easier.

      Here's an example of how you might set it up:


      ------------------------------
      Evan Westbrook
      PRIME Developer
      Harder Mechanical Contractors Inc.
      Portland OR
      ------------------------------
      • IvanWeiss's avatar
        IvanWeiss
        Qrew Captain
        Evan, thanks for the SUPER DETAILED response again!  So here is my challenge....  I have several different clients I need to maintain the relationship for.  Not all of them have the same structure level.

        So my concern with the separate table is one of my client uses RVP and DM as the levels.  Another one of my clients use SVP, Vice President of Operations, and DM as the three levels (they have an extra one).

        So in a separate table approach could it intelligently understand this or does that push me to the self related table approach?

        If I go with the self table relationship....  I think I would relate "down" stream correct?  So on the contact I would have a one to many relationship to contacts and that relationship would be direct reports and that would be the level down (DM's in the first example above)

        ------------------------------
        Ivan Weiss
        ------------------------------