Is it possible to return the relations in all cases?

System Information
  • Strapi Version: 4.16.2 (I can’t update because of a bug in the admin UI introduced in version 4.17)
  • Operating System: Mac OS Sonoma or Ubuntu 20.4
  • Database: PostgreSQL
  • Node Version: 20.9
  • NPM Version: 10

I’ve already encountered several bugs in my code because of the fact that relations are not returned by default. They are not returned when you make a simple GET API request to /api/mymodel. They are not present when you update a model, even if the admin UI shows the relation.

Is there a way to globally change this default behavior, such that relations are always present in all possible cases (such as simple GET request, on model update or any other case I can’t think of because of my limited knowledge of Strapi)? I don’t really care about performance now and there should be an option to enable this behaviour. Could maybe this be done in the model’s controller? I don’t know if all requests go through these controllers or not, but I would assume yes, so the Strapi UI also uses them?

I think what you are referring to is that when making a GET request it does not return the fields that are relationships in your model. For a GET request to return those relationships you can do the following:

/api/mymodel?populate=*

In this case it will return all the entities related to the model.
I hope I’ve helped.