Reputation: 39
I’ve recently discovered Strapi and I am trying to use it to create a company website, but I’ve got stuck while trying to design the backend structure.
The company offers some packages structured on many levels (like the table from the image)

I want all of those items stored in the database and be easily updated or removed. I’ve created 4 collection types: packages, package items, packages levels, packages categories.



Everything work as expected, so, I’ve created a component PackageHome that I want to use in another Collection Type: Pages. I want a component to allow me to select some packages and to select one level for each one of them and some items. All those are meant to be used by the client app.

The problem is that even if the "package item" collection type contains the package level relation, I not able to see the levels at which the item “is available”/contained by a level’s package. I can see them in the packages items API, but using components I am not and do not know why.
This is what I receive from PackageHomeComponent:

This is what I want to receive from the component and I receive in the Packages Items API endpoint:
Is there a structural design problem? How can I solve it?
Upvotes: 0
Views: 1089
Reputation: 39
I've solved my dilemma by writing a custom controller in which I've enriched the data that was sent through API to the frontend. I've also found out that I could write a plugin with which I've to create another field that lets me choose what I want. I've started working but I didn't finish because I've found this easier solution. Anyway, the plugin (a custom field) is the solution for the long term and a more elegant approach.
P.S: I've followed this doc: https://strapi.gitee.io/documentation/3.0.0-beta.x/concepts/controllers.html#core-controllers
Upvotes: 0