¿Hay alguna manera de completar el campo al actualizar,
... const response = await cartService.update(id, { data: { items } }); const sanitizedEntity = await this.sanitizeOutput(response, ctx); return this.transformResponse(sanitizedEntity);Puede hacer esto adjuntando populate=[your_relational_field] como query string en la llamada de solicitud http PUT .
http://localhost:1337/api/cart/2?populate=category
{ "data": { "items": "items data here" } } ¡Eso es todo! Ni siquiera necesita anular el método de actualización central en su controlador y StrapiV4 recogerá directamente la cadena de consulta. Pero en caso de que, por alguna razón, haya anulado el método de update central del controlador, simplemente puede pasar la instancia de ctx a la update central o métodos findOne como se muestra a continuación:
"use strict"; /** * cart controller */ const { createCoreController } = require("@strapi/strapi").factories; module.exports = createCoreController("api::cart.cart", ({ strapi }) => ({ async update(ctx) { // let's say you've written some custom logic here // finally return the response from core update method const response = await super.update(ctx); return response; // OR // You can even use the core `findOne` method instead const response = await super.findOne(ctx); return response; // OR // if you've used some other service then you can pass in the populate option to the update method const response = await cartService.update(id, {data: { items }, populate: "items.product" }); return response; }, }));