-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
- I have created my request on the Product Board before I submitted this issue
- I have looked at all the other requests on the Product Board before I submitted this issue
Hello everyone!
It would be really interesting to easily manage hierarchical content.
Currently, with the "has many" relationship, you can easily set up a parent/child link between two entries of the same collection, here is an example for a page collection :
An item can have one parent, and several children. This can be useful when you want to set up a page tree system for example, it allows to manage urls thanks to the hierarchy.
But it would be much more convenient, if it was possible to look and manage these relationships directly from the list view of the collection. For example, the WordPress Nested Pages extension, offers an interface and drag & drop for this :
Come to think of it, on Strapi's side, it might look something like this :
Parent/child relationships could be managed by drag & drop, as well as the order of entries (linked with this feature request : #3946). We could also fold the groups of entries.
To do this, one could imagine that additional options would be available to make a collection hierarchical and sortable. This could create implicit fields: parent / children / order, which would be updated when dragging & dropping.
This offers several possibilities at the API level: retrieving children of an element, retrieving an element according to its parent etc...
It also gives the possibility to generate fields thanks to the hierarchy, here is a basic example :
// page.js
module.exports = {
beforeSave: async (model, attrs, options) => {
let fullSlug = "";
// here we update the field "full_slug", by concatenating the parent's one
if (model.relations && model.relations.parent) {
const parent = model.relations.parent;
const parentSlug = parent.attributes && parent.attributes.full_slug;
fullSlug = `${parentSlug}/${attrs.slug}`;
} else {
fullSlug = attrs.slug;
}
if (options.method === "insert") {
model.set("full_slug", fullSlug);
} else if (options.method === "update") {
attrs.full_slug = fullSlug;
}
},
};the most common case, would obviously be the management of page trees, but also, for example, the hierarchy of documents, a list of employees, etc.

