Reputation: 3126
Here's the data involved,
Here's the schema I have come up with
id name (example : regional ...)
id, name (example : resources), scope_id
id, name (example : legal, sponsored ...), category_id
The problem is, as you can see, there are a lot of repeated data as the same category appears under all scopes, same sub categories appear under all categories. Of course, there will a few unique values in the case but they are very few. Also, even though the name of the category/sub category is same they will be holding references to different set of data depending on their parent scope/category. This will be used in segregating the content and generating a menu to browse those contents. What I want to know is if this is a proper way to address this or there are better ways/schema anyone can suggest me?
Upvotes: 1
Views: 149
Reputation: 6240
Based on the limited information you've provided, this is what I'd do:
categories
id unsigned int(P)
name varchar(15)
+----+-----------+
| id | name |
+----+-----------+
| 1 | Assets |
| 2 | Resources |
| .. | ......... |
+----+-----------+
categories_subcategories
id unsigned int(P)
category_id unsigned int(F categories.id)
subcategory_id unsigned int(F subcategories.id)
+----+-------------+----------------+
| id | category_id | subcategory_id |
+----+-------------+----------------+
| 1 | 1 | 4 |
| 2 | 1 | 1 |
| .. | ........... | .............. |
+----+-------------+----------------+
levels
id unsigned int(P)
name varchar(15)
+----+----------+
| id | name |
+----+----------+
| 1 | National |
| 2 | Regional |
| 3 | Zonal |
| .. | ........ |
+----+----------+
levels_categories
id unsigned int(P)
level_id unsigned int(F levels.id)
category.id unsigned int(F category.id)
+----+----------+-------------+
| id | level_id | category_id |
+----+----------+-------------+
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| .. | ........ | ........... |
+----+----------+-------------+
subcategories
id unsigned int(P)
name varchar(15)
+----+-------------+
| id | name |
+----+-------------+
| 1 | Contributed |
| 2 | Financial |
| 3 | Legal |
| 4 | Sponsored |
| .. | ........... |
+----+-------------+
Upvotes: 1