Hello,
How do you create a collection with nested categories such as
Food
Desserts
Cookies
Cakes
Pies
Is there any documentation you can point to? What I’ve read so far makes it seem like children categories will all be at the same level as the parent categories.
creating multiple collection is not practical. since you will have to create new collection for every level
the deeper nested you go, the more collection you will have…
i prefer to have 1 collection only:
Create collection “Category”
Add relational field called “parent”. this field is “many-to-one relation” with the same “Category” collection. (it will read as “Category has many Categories” in strapi)
now when you enter the data:
enter “Desserts” and leave the parent field blank
Enter “Cookies” and choose “Deserts” from the Parent field drop down
To get your data in the api, you should populate the parent field
and that’s it …now u can add as many levels as you want.
Note: if you want the same sub-category falls under different categories (for example category Diet under Food and under Sweets) then choose many-to-many relation
Hi, does it work also if doing belongs to many? so we can have also the parent category inside each category…
Because as you said you can have children but in rest api there will be visible children separately also.
You can create a reaction category (parent) - has many - category (children)
That way you can create a category like Fashion
Another one like Male with parent Fashion
when you see the Fashion category will note that the field children will point to the Male and in Male category you will see Fashion as parent, you can also do it to Male, creating t-shirts with male parent, and so on…