如何在Strapi中发布关系

时间:2019-07-17 14:18:09

标签: javascript sqlite strapi

我正在尝试对Strapi API进行POST,似乎无法弄清楚如何附加“具有并属于许多”(多对多)关系。

我已经尝试过以下身体:

events: ["ID", "ID"]
name: "name"

events: [ID, ID]
name: "name"

我认为关于docs应该正确。

没有错误,我收到“ 200 OK”响应。它添加了记录,但没有关系。

Event.settings.json:

{
  "connection": "default",
  "collectionName": "events",
  "info": {
    "name": "event",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": [
      "created_at",
      "updated_at"
    ],
    "comment": ""
  },
  "attributes": {
    "name": {
      "type": "string"
    },
    "artists": {
      "collection": "artist",
      "via": "events",
      "dominant": true
    }
  }
}

Artist.settings.json:

{
  "connection": "default",
  "collectionName": "artists",
  "info": {
    "name": "artist",
    "description": ""
  },
  "options": {
    "increments": true,
    "timestamps": [
      "created_at",
      "updated_at"
    ],
    "comment": ""
  },
  "attributes": {
    "name": {
      "required": true,
      "type": "string"
    },
    "events": {
      "collection": "event",
      "via": "artists"
    }
  }
}

我使用的是标准SQLite数据库(strati版本3.0.0-beta.13),并尝试通过Postman,HTML和curl进行请求。

我很想知道如何在POST上附加关系

1 个答案:

答案 0 :(得分:0)

我认为这是因为您将ID设置为 String ,而不是 Integer

{
  events: [1, 2],
  name: "My name"
}

这里12是您要添加的事件IDs