我正在尝试对 Strapi API 进行 POST,但似乎无法弄清楚如何附加“拥有并属于许多”(多对多)关系。
我已经尝试过以下 body :
events: ["ID", "ID"]
name: "name"
&events: [ID, ID]
name: "name"
其中关于docs应该是对的,我想。没有错误,我得到“200 OK”响应。它添加了记录但没有关系。
事件.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
}
}
}
艺术家.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 数据库,strapi 版本 3.0.0-beta.13,并通过 Postman、HTML 和 curl 尝试了请求。我很想知道如何在 POST 上附加关系
23-07 更新:
全新安装了 Strapi,现在一切正常。
最佳答案
我想是因为你设置了你ID
作为 字符串 而不是 整数
{
events: [1, 2],
name: "My name"
}
在这里
1
和 2
是IDs
您要添加的事件。
关于javascript - 如何在 Strapi 中发布关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57078064/