我正在尝试写一篇关于Strapi API的帖子,但我似乎想不出如何附加一个“拥有并属于多个”(多对多)的关系。
我已经尝试了以下身体的:
events: ["ID", "ID"]
name: "name"
&
events: [ID, ID]
name: "name"
我认为,关于医生的这一点应该是正确的。
没有错误,我得到的响应是‘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数据库,stRapi版本3.0.0-beta.13,并通过Postman、HTML和cURL尝试了该请求。
我想知道如何将这种关系贴在帖子上
更新23-07:
重新安装了Strapi,现在一切正常。
2条答案
按热度按时间xesrikrc1#
我认为这是因为您将
ID
设置为字符串而不是整数这里的
1
和2
是您要添加的IDs
事件。scyqe7ek2#
回复晚了。希望这能帮到什么人!
现在我正在使用Strapi v4.3.2,也面临着同样的问题。我克服了这个问题,如官方文档中所述,覆盖了创建的默认核心控制器。现在可以看到关系了!