I have a hierarchical relationship between my tables, with the children having foreign keys referring back to their parent ids (assuming id
is the primary key for each table):
Department
has many Category Group
sCategory Group
has many Category
(-ies)Category
has many Sub-Category
(-ies)Sub-Category
has many Attribute
s.
Now, all these entities except for Attribute
s are optional meaning if I don’t select anything on my hierarchical cascading dropdown based UI, I need to display the Attribute
s that belong to all Department
s, if I only select a Department
then I need to display Attribute
s that belong to all Category Group
s belonging to that Department
and so on.
Obviously, one option to implement it is to do a inner join between all the tables to get to Attribute
. For instance, if nothing is selected it will be:Department
inner join Category Group
inner join Category
inner join Sub-Category
inner join Attribute
to show all the attributes belonging to all departments.
The other thought in my head is to have intersection/relation mapping table(s) –DepartmentAttributeRelation
which has foreign keys to Department
and Attribute
,CategoryGroupAttributeRelation
which has foreign keys to CategoryGroup
and Attribute
and so on.
This will enable direct search to get to the Attribute
s given any entity.
My question is – Are there any downsides to the second approach above or are there any better approaches to solve this?
Go to Source
Author: linuxNoob