i have a user collection that holds many relations that i want to retrieve and i can do that by using populate=*
but i also need to populate a relation within a realtion and i dont know how to do both of those in one request so i can get all one level deep relations populated and that 2 level deep relation populated as well
This topic has been created from a Discord post (1270095262848909424) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
i tried this http://localhost/api/users?populate=*&populate[grupy][populate]=zestawy_cwiczens
but got error:
2024-08-05 21:07:14 [2024-08-05 19:07:14.459] error: Invalid populate parameter. Expected a string, an array of strings, a populate object
2024-08-05 21:07:14 Error: Invalid populate parameter. Expected a string, an array of strings, a populate object
2024-08-05 21:07:14 at /opt/node_modules/@strapi/utils/dist/convert-query-params.js:187:23
2024-08-05 21:07:14 at Array.flatMap (<anonymous>)
2024-08-05 21:07:14 at convertPopulateQueryParams (/opt/node_modules/@strapi/utils/dist/convert-query-params.js:185:47)
2024-08-05 21:07:14 at transformParamsToQuery (/opt/node_modules/@strapi/utils/dist/convert-query-params.js:448:26)
2024-08-05 21:07:14 at Object.findMany (/opt/node_modules/@strapi/strapi/lib/services/entity-service/index.js:87:19)
2024-08-05 21:07:14 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-08-05 21:07:14 at async Object.<anonymous> (/opt/node_modules/@strapi/strapi/lib/services/entity-service/index.js:417:20)
2024-08-05 21:07:14 at async Object.find (/opt/node_modules/@strapi/plugin-users-permissions/server/controllers/user.js:147:19)
2024-08-05 21:07:14 at async returnBodyMiddleware (/opt/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
2024-08-05 21:07:14 at async policiesMiddleware (/opt/node_modules/@strapi/strapi/lib/services/server/policy.js:24:5)
it should be something more like this GET /api/articles?populate[category][populate][0]=restaurants
yes i did and it nowhere specifies how to do what i need
this only populates restaurants under categories in articles
converting this to my case this would only populate the zestawy_cwiczens under grupy in user, but i also want all other relations that user has
you then need to add all your other relations in the url
/api/articles?populate[category][populate][0]=restaurants&populate=other
I use to write all the attributes with qs library in js, not on the url directly
it’s on the documentation too (qs - npm)
populate[0]=relation-name&populate[1]=another-relation-name&populate[2]=yet-another-relation-name
yea i already done that, but i have to write all relations by hand - cant use the wildcard (*)
if you only put populate=*
it doesn’t give you all the relations ?
If i put only this then it does
But i also need that 2 level deep relation
If you need to always do this for that service call, you can do an override on the controller of the find method(s) and write the code to retrieve the relations you need using the Entity Service API, which would be a lot more readable and manageable than the query string salad you’re going to have to put together for this
aha it is indeed a query string salad sometimes 