node.js - Strapi 关系不返回正确的层次结构
问题描述
我正在尝试创建以下关系模型:
Section has many categories
Categories has many sub-categories
所以基本上我们在这里有三个集合:
- 部分
- 类别
- 子类别
首先,我定义了Section
和之间的关系Category
:
然后,我创建了Category
and之间的关系SubCategory
:
我也填充了这些集合,当我打电话时,http://localhost:3002/sections
我得到:
[
{
"id": 1,
"name": "ambition",
"published_at": "2020-11-20T10:21:08.000Z",
"created_at": "2020-11-20T11:21:06.000Z",
"updated_at": "2020-12-01T10:26:44.000Z",
"description": null,
"featured_image": null,
"categories": [],
"subcategories": []
},
{
"id": 2,
"name": "the_tanning_of_the_future",
"published_at": "2020-11-20T10:21:19.000Z",
"created_at": "2020-11-20T11:21:18.000Z",
"updated_at": "2020-12-01T10:27:15.000Z",
"description": null,
"featured_image": null,
"categories": [],
"subcategories": []
},
{
"id": 3,
"name": "living_sustainable",
"published_at": "2020-11-20T10:21:28.000Z",
"created_at": "2020-11-20T11:21:26.000Z",
"updated_at": "2020-12-01T10:27:31.000Z",
"description": null,
"featured_image": null,
"categories": [],
"subcategories": []
},
{
"id": 4,
"name": "creativity",
"published_at": "2020-11-20T10:21:36.000Z",
"created_at": "2020-11-20T11:21:34.000Z",
"updated_at": "2020-12-04T10:53:32.000Z",
"description": null,
"featured_image": null,
"categories": [
{
"id": 1,
"name": "Archivio",
"published_at": "2020-11-20T10:57:34.000Z",
"created_at": "2020-11-20T11:22:48.000Z",
"updated_at": "2020-12-04T10:50:50.000Z",
"subcategory": null,
"feature_image": null
},
{
"id": 2,
"name": "Colori",
"published_at": "2020-11-20T10:57:37.000Z",
"created_at": "2020-11-20T11:22:55.000Z",
"updated_at": "2020-12-03T11:55:11.000Z",
"subcategory": null,
"feature_image": null
},
{
"id": 3,
"name": "Lifestyle",
"published_at": "2020-11-20T10:57:39.000Z",
"created_at": "2020-11-20T11:23:02.000Z",
"updated_at": "2020-12-03T11:55:20.000Z",
"subcategory": null,
"feature_image": null
}
],
"subcategories": [
{
"id": 1,
"name": "Inverno 21",
"published_at": "2020-12-03T15:16:57.000Z",
"created_at": "2020-12-03T11:52:13.000Z",
"updated_at": "2020-12-03T15:16:57.000Z",
"category": 1,
"description": null
},
{
"id": 2,
"name": "Estate 21",
"published_at": "2020-12-03T11:54:42.000Z",
"created_at": "2020-12-03T11:54:36.000Z",
"updated_at": "2020-12-03T15:14:04.000Z",
"category": 1,
"description": null
}
]
}
]
从响应中可以看出,Section
和之间的关系工作正常,但和Category
之间的关系不正常。事实上,我已经定义了这些模型之间的 1:n 关系,但我得到:Category
SubCategory
{
"id": 4,
"name": "creativity",
"published_at": "2020-11-20T10:21:36.000Z",
"created_at": "2020-11-20T11:21:34.000Z",
"updated_at": "2020-12-04T10:53:32.000Z",
"description": null,
"featured_image": null,
"categories": [
{
"id": 1,
"name": "Archivio",
"published_at": "2020-11-20T10:57:34.000Z",
"created_at": "2020-11-20T11:22:48.000Z",
"updated_at": "2020-12-04T10:50:50.000Z",
"subcategory": null,
"feature_image": null
},
另一个奇怪的事情是,在仪表板中,我实际上可以将子类别与 selected 相关联Category
,请参阅:
所以我应该有回应:
{
"id": 4,
"name": "creativity",
"published_at": "2020-11-20T10:21:36.000Z",
"created_at": "2020-11-20T11:21:34.000Z",
"updated_at": "2020-12-04T10:53:32.000Z",
"description": null,
"featured_image": null,
"categories": [
{
"id": 1,
"name": "Archivio",
"published_at": "2020-11-20T10:57:34.000Z",
"created_at": "2020-11-20T11:22:48.000Z",
"updated_at": "2020-12-04T10:50:50.000Z",
"subcategories": [
...
],
"feature_image": null
},
我做错了什么还是 Strapi 的关系引擎有问题?
解决方案
推荐阅读
- php - 显示问题取决于客户的角色 - woocommerce
- javascript - Touch Slider 上的滚动问题
- r - 数据框中的数据格式
- bazel - bazel 会截断或附加到现有的 build_event_json_file 吗?
- build - 错误:expo buidl 时请求失败,状态码为 400
- gecko - Gecko:如何获取请求(而不是响应)标头?
- angular - 在 Angular 中访问隐藏的标头参数
- r - 在R中计算碳随时间的半衰期
- c# - 如何使用特殊字符:在 Url C# webApi 中
- c# - Http Post 永远不会从 Twilio 返回,但会执行 Twilio 操作