What would be the best way to create a database and relationships for a site like Yelp or eBay (many categories and subcategories)?

Do they have a table for all categories and another for all sub-categories (and another for sub-categories, etc.) or what? How do all levels interact with each other?

I am starting to work on a project that can have such a level of complexity, and from time to time it revolves around this.

I work with Rails, but I also appreciate answers in database schemas, pointers for further reading, etc.

+3
source share
2 answers

I assume that you are dealing with hierarchical data here.

. . :

CategoryID CategoryName ParentCategoryID
----------------------------------------
1          Computers    NULL
2          Programming  1
3          Games        1
4          Python       2

, . :

CategoryID ItemID Description
----------------------------------------------
4          1      Book – Programming in Python
3          1      World of Warcraft

, . " ". , (, Python -/Computers/Programming/Python) ( ). , , SQL. , .

( " " ). , " MySQL" , , ( "Adjacency List" "Nested Set" ).

+4

- , " " .

, A, B ( A).

, , , , A, B Cat_ID Sub_ID .

, , , , , Product_Categories product_id category_id. ( ) table, product_subcategories, sub sub, sub sub sub, blah blah blah .. .. ..

+1

All Articles