Hello, Is there a way to retrieve id of relations (many-to-many and one-to-many) without populating them without using graphql?
My problem is: I have a lot of products that are related to many categories.
I have only 10 categories, so they are all fetched once and stored in my app.
When I fetch product, I don’t want Strapi to make a join query to populate the categories (for performances issues), but I need those IDs.
If I query directly my /products endpoints, categories are populated by default
But, If I make a relation on a single type with those products, categories are not populated (neither ids …)
Edit: I saw that there is another table that is called products_categories__categories_products but how we can query it ?
Hum, unfortunately this does not solve my problem: doing so will make a join query to retrieve only IDs which is overkill because we already have them (IDs are needed for making the join query)
"autoPopulate": false removes the attribute entirely, but what is needed is the list of id’s.
For example, the correct output should be - "someAttributeName": [1,2,3,4,5]
Just to be clear: the goal is to have only the ids of the relationship while avoiding an extra unnecessary read to the DB for performance reasons.
I believe it can’t be done in only one read because the relationship is not stored in one column, it is stored in another table.
For example products and categories would be split in 3 tables:
categories
products
products_categories__categories_products (where the relationship is stored)
But still when calling categories and extra call to products could be avoided by just calling products_categories__categories_products and returning the ids without populating it. And this is where we are stuck.
It may sound like not much, but is causing me and extra 1000+ unnecessary DB reads in a very requested endpoint.
Any solution to alleviate the problem would be welcome, no matter how hacky it feels
@sunnyson I don’t think it’s a good idea as it is one more query or join table. I want only the ids, really, but i think that if I query populate=myrelation.id, it will do one my query (or join) anyway. I would love to avoid that extra query. but, from what I saw until here, it’s not possible in v4.