Relation between content type created by an app User and admin User

System Information

  • Strapi Version: 3.5.4
  • Operating System:
  • Database: mongo
  • Node Version: 12.16.1
  • NPM Version:
  • Yarn Version: 1.19.1

Hi there,

I am trying to create programticaly a relation between a content type and an Admin User.
I want than an app user (Authenticated/Public) create a content who can be administrate by an Admin panel User after the creation.

I have the id of the Admin panel User when I do the POST with the app user so in theory I can do this.
I followed this tutorial

But I do not know why it doesn’t works.
My controller to create a comment :

const { parseMultipartData, sanitizeEntity } = require('strapi-utils')

module.exports = {
  /**
   * Create a record.
   *
   * @return {Object}
   */

  async create(ctx) {
    let entity
    if (ctx.is('multipart')) {
      const { data, files } = parseMultipartData(ctx)
      data.userAuthor = ctx.request.body.created_by
      entity = await strapi.services.comments.create(data, { files })
    } else {
      ctx.request.body.userAuthor = ctx.request.body.created_by
      entity = await strapi.services.comments.create(ctx.request.body)
    }
    return sanitizeEntity(entity, { model: strapi.models.comments })
  },
}

So when i create a comment, the relation is well done and I have the good ID in my userAuthor field

As you can see the ID in my comment is the ID of an admin strapi user

But when I am loged with this admin I can not see the comment created

Here a screen of the relation about comment and admin user :

I’m stuck with that, if some one have an idea

Thanks in advance

1 Like