Posting relation with id create new entry in database

System Information
  • Strapi Version: 3.6.8:
  • Database: Sqlite:

I am using component to build my relation like this:

{
  "kind": "collectionType",
  "collectionName": "books",
  "info": {
    "name": "Books",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": true,
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "booktitle": {
      "type": "string"
    },
    "authors": {
      "type": "component",
      "repeatable": true,
      "component": "books.authors"
    }
  }
}

The problem is when I am creating a new book, even when I add the ID of author like below, it doesn’t care, and will create a new author with new ID, but if I send a put request with the same JSON structure it notice the ID and will not create a new author record! Why it is not working in post request? Am I missing something?

JSON data, which I use for POST and PUT request:

{"booksubtitle":"test","authors":[{"id":4,"author":"test author"},{"id":5,"author":"1"},{"id":6,"author":"2"}]}

The POST response:

{
    "id": 5,
    "booktitle": "test",
    "authors": [
        {
            "id": 13,
            "author": "test author"
        },
        {
            "id": 14,
            "author": "1"
        },
        {
            "id": 15,
            "author": "2"
        }
    ]
}

The PUT response:

{
    "id": 2,
    "booktitle": "test",
    "authors": [
        {
            "id": 4,
            "author": "test author"
        },
        {
            "id": 5,
            "author": "1"
        },
        {
            "id": 6,
            "author": "2"
        }
    ]
}

Small question, why are you using components for this instead of just a manyWay relation. I feel like this would cause a lot of complexity and duplication of data.

Because in the Strapi admin UI it is easier for the user, but it seems the use case of component are very limited.

You may put like this, it worked totally perfect with me:

{"booksubtitle":"test","authors":[4,5,6]}

The point is: you can not create new items regarding your relation, you can only refer to them with their ids.