How can I model this class in a database?

后端 未结 4 1623
猫巷女王i
猫巷女王i 2020-12-12 02:33

I need a little of help. This is my design to organize several categories.

   Category 1
     Sub Category 1.1
       Sub Category 1.1.1
     Sub Category 1.         


        
4条回答
  •  庸人自扰
    2020-12-12 03:12

    I'd use a simple Recursive Relation. Each Category should have a unique ID (primary key) and an optional field specifying its parent, which would be a foreign key mapping back to the same table. Categories with a NULL parent are top-level categories.

    The page I linked to also has information on how you can query this structure to find top-level or mid-level Categories.

提交回复
热议问题