1
votes

I have a menu in the database like everyone else:

id parent_id url
1 0 clothes
2 1 men
3 2 pants
3 1 women
4 3 pants

I'm coming web.com/clothes/men/pants, I catch the url in the controller:

It is very inconvenient to always collect all the URLs:

  • For the menu
  • To understand what category we are in in order to show the product correctly

Maybe should I immediately store the full urls in the database?

There are 1800 categories in total! And cache everything!

id parent_id url
1 0 clothes
2 1 clothes/men
3 2 clothes/men/pants
3 1 clothes/women
4 3 clothes/women/pants
1

1 Answers

0
votes

The menu is composed of heirarchial elements at different levels. Therefore, a logical approach would be to store them in separate tables depending on there level, so:

Level 1:

Clothes

Level 2:

Men

Women

Level 3:

Pants

This hybrid approach makes construction of the taxomic levels easy without the brute force of storing thousands of full url paths that will be hard to maintain.