Creating categories and subcategories

I’m trying to create the categories collection on the surface, I mean before delving into any coding. So I’m following some AI generated hints:

  1. Create a Collection: Go to Settings → Data Model and create a new collection called Categories.
  2. Add Name Field: Add a Text Input field called Name.
  3. Add Relationship Field: Add a Many-to-One field (labeled “Parent Category” or similar).
    • Related Collection: Select Categories (yes, it links to itself).
  4. Configure Interface: Ensure the field allows selecting another item from the same Categories collection.
  5. Set Up Tree View (Optional): In the collection settings, go to the “Layout” tab, choose Tree, and select the “Parent Category” field as the parent ID. This provides a visual folder-like structure in the content module.

Problem is already at step 3, because in the relationship > related collection field my collection is greyed out. Is it because it needs to be coded first? What am I missing.

Steps sounds correct, not sure why your collection is greyed out, did you create it within Directus? are you able to create new items in the categories collection?

if not, you just need to click on the collection to “configure” it and that’s it.

I read that sometimes they are greyed out but they can be inserted manually, which I did. I now seem to have created my categories/subcategories manually, and also have set the parent/child fields. I also created items. However I’m now struggling with the “Tree View” and “Group by” options which are not visible in the layout option. I have checked everything also at the server’s level and the extension is installed… I simply do not see the layout option in the single fields neither in the collections/items list.

Any hint?

I see, many people complained about the the same issue

So I would recommend uninstalling it (since it crashes other extensions for me) and use this extension which I personally use Hierarchy Layout until they fix the official one.

Thanks for the tip (I had wondered why there were zero downloads on the Tree View extension). I have now installed Hierarchy and it seems to work, showing me the payout option. It actually facilitates the creation of a child category because it adds a + into the parent field, so to pick the parent category at once :upside_down_face: I still see no “tree view” option in the “parent” field of the single collection, but at least I have it in the Content layout page

Can you approve that you made it a self relation? as the AI suggested here?

  1. Add Relationship Field: Add a Many-to-One field (labeled “Parent Category” or similar). * Related Collection: Select Categories (yes, it links to itself).

Cause afaik both extensions works for self relations only.

Yes I confirm that the relation was to the category itself (though I inserted the text manually as it was greyed out… which was also an AI suggestion, so it might be it’s a bug as well)

hello again, after I created the catg+subcatg, which looks nice in “herarchy” view", when viewing them as a table I initially get them with parent/child names and IDs, but then also duplicated, with empty fields (see screenshot). Is this normal or something is wrong?

Hello @Criss once again
I’m not sure how your current build, but you should look like the following:


self relation for the parent and child, the parent is m2o, and the children is the reverse (o2m)

You just need to adjust the display for both fields and it should look like this in the Hierarchy layout


And something like that in the Table layout

Goodday @Abdallah Hovering the mouse on the items, parents are set “Integer/M2O”, and childs are “Alias/TreeView”. Is that already wrong? I have set the “display template” to just show “name” and I do see the items counts, however I still get “duplicated” fields in Table view. I read that the issue is due to Directus showing “joins” of the database and I have played with the filter, but I wish not to do that because it influences the Hierarchy view as well.

According to my knowledge/approach yes, I would delete the current setup (after you take a backup) and just make a o2m relation and make sure to press on the create corresponding field and it should work fine after you setup the display to properly show the name
Give it a try and let me know if you still have issue.

I have built a lot of collections intertwined with these categories, so I cannot rebuild them. However, the interface of the child field tells me that the TreeView is actually a O2M. So I think it’s only a matter of playing with the table output, in order to hide the child items from the first column. Do you (or anyone) have other suggestions?

I have decided to follow @Abdallah suggestion and have deleted all parent/child and have recreated the M2O/O2M fields. I have succeeded in fixing the table/hyerarchy views, not it looks as it should be:

I believe this thread is resolved! :star_struck: