Search code examples
strapi

is there a way to link the created_by field that gets auto generated to users (create a relation) rather than it being related to the admin Users?


I'm new to Strapi tried creating a new collection and updating a value using postman for my endpoint.

The problem I'm having is that the "created_by" field seems to get auto-generated and will not allow me to update it using a created user credentials/id but it always picks the admin id.

I'm lost on this how can you relate the "created_by" field to your defined users rather than the admin table?


Solution

  • You shouldn't use "created_by" field.

    You need a relation field between users and collection

    Such as :

    Relation with User (from: users-permissions)
    

    relation with user


    Please check this "many to one relation" example.

    many to one relation example

    So projectroot\api\bird\models\bird.settings.json will have the following lines:

    "user": {
          "via": "birds",
          "plugin": "users-permissions",
          "model": "user"
        },