Why is a parent collection relation ID not showing up in api call?

System Information
  • Strapi Version: 4.9.2
  • Operating System: Windows 11, x64
  • Database: postrges
  • Node Version: v16.17.0
  • NPM Version: 8.18.0
  • Yarn Version: None


I create a collection X and Y. In X I added a relation field “X has and belongs to one Y”. I also made sure the relation is not marked as private. When I call public api findOne on X, the ID of Y is not returned. I read that I have to use the populate query, but in order to do so, I must also open public find api for Y. But I do not want the client side to be able to do find calls on Y (getting a list, etc.).

This all at moment doesn’t make much sense to me, because ideally the ID should be there without populating query, and if I do populate findOne on Y should be enough.

Maybe someone can shine a light on this for me and suggest something, please.

strapi ignores the ids inside relations since in strapi every relationship has a joining table so that they can save metadata of the relation

aka the id in the id field is the id to the joining table not the id to the other relation

1 Like

Do you know a solution to add this Y relation ID in response? Without exposing Y to find endpoint?

Nop but you can enable find and then add a policy that returns false to the find route
what will cease the route not to be useable and then it will be useable in the entity service

1 Like

How do I add this policy? Do you have a snippet or link to get me started on this?