Forum Discussion
IvanWeiss
6 years agoQrew 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
------------------------------
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
6 years agoQrew 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
------------------------------
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
------------------------------
- IvanWeiss6 years agoQrew CaptainEvan, 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
------------------------------- EvanWestbrook6 years agoQrew CadetIvan,
I'm glad you appreciated the details. I get a little excited about data stuff sometimes.
To answer your question: yes, the separate table approach would handle varying structure levels for different companies.
If we think about this on a really high abstraction level, this use case is just describing how entities are related to other entities (sounds like a database!) With corporate management structures, we're tracking how employees are related to other employees. Specifically, who reports to whom. Since this doesn't require an employee's title (at least in the eyes of the database,) we can handle the corporate structures of different organizations in the same table. Said another way, the corporate hierarchy of Company A and B are implicit in the "Contact Hierarchy" table.
Here's a quick example:
- Company A:
- Structure:
- RVPs report to VPs
- Contacts and Title:
- Diane (VP)
- Todd (RVP)
- Structure:
- Company B
- Structure:
- DMs report to VPs
- Contacts and Title:
- Caroline (VP)
- Bo (DM)
- Structure:
- Record 1
- Supervisor: Diane
- Direct Report: Todd
- Record 2
- Supervisor: Caroline
- Direct Report: Bo
------------------------------
Evan Westbrook
PRIME Developer
Harder Mechanical Contractors Inc.
Portland OR
------------------------------ - Company A: