Strapi v4 custom controller entityLink issue

System Information
  • Strapi Version: v4
  • Operating System: MacOs
  • Database: Sql
  • Node Version: 16
  • NPM Version:
  • Yarn Version:

Hi everyone,

I run into an issue with strapi v4. I want to create a controller for an entity that have a relation with the user, it’s set according to the user that made the request. However the code does not work


/**
 *  simulation controller
 */

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('api::simulation.simulation', ({strapi}) => ({
    async create(ctx) {
        const user = ctx.state.user
        ctx.request.body.data.user = {id: user.id}
        const entity = await super.create(ctx);
        return entity;
    }
}));

I found how to, I needed to use the entityService

    async create(ctx) {
        const user = ctx.state.user
        ctx.request.body.data.user = user.id
        const entity = await strapi.entityService.create('api::simulation.simulation', ctx.request.body);
        return entity;
    }