Skip to content
Advertisement

strapi 4 populate when update

Is there an way to populate the field when updating,

JavaScript

Advertisement

Answer

You can do this, by attaching the populate=[your_relational_field] as the query string in the http PUT request call.

Sample request

http://localhost:1337/api/cart/2?populate=category

Sample request body in JSON format
JavaScript

That’s all! You don’t even need to override the core update method in your controller and the query string will directly be picked up by StrapiV4. But in case for some reason you’ve overridden the core update method from the controller, then you can simply pass the ctx instance to the core update or findOne methods like below:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement