组件和动态区域不会返回 id
🌐 Components and dynamic zones do not return an id
Page summary:在 Strapi 5 中,组件和动态区域在 REST API 响应中不再返回
id,这阻止了部分更新,并要求必须发送完整的组件对象。🌐 In Strapi 5, components and dynamic zones no longer return an
idin REST API responses, preventing partial updates and requiring full component objects to be sent instead.
在 Strapi 5 中,组件和动态区域在 REST API 请求中不会返回 id,因此无法对它们进行部分更新。
🌐 In Strapi 5, components and dynamic zones do not return an id with REST API requests so it's not possible to partially update them.
此页面是重大更改数据库的一部分,提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。
🌐 This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.
重大变更描述
🌐 Breaking change description
在 Strapi v4 中
在 Strapi v4 中,你可以通过传递其组件 id 来部分更新组件。
🌐 In Strapi v4, you can partially update a component by passing its component id.
在 Strapi 5 中
REST API 中组件和动态区域的响应不包含 id,并且无法对它们进行部分更新。
🌐 The response of components and dynamic zones in the REST API does not contain an id, and partial updates on them is not possible.
迁移
🌐 Migration
本节重新组合了有关引入的重大更改的有用说明和程序。
🌐 This section regroups useful notes and procedures about the introduced breaking change.
注意
🌐 Notes
-
在 Strapi v4 中,你可以执行以下操作来发送请求,这些请求将返回组件的
id:// 1. GET /category/:id
category = fetch(...)
// 2. PUT /category/:id
{
data: {
name: 'category-name',
// Update component by its id
component: {
id: category.component.id // Use the id received in 1.
value: 'value'
}
}
}所以你可以指定组件
id来更新value字段。 -
在 Strapi 5 中:
- 草稿 & 发布 功能已被重新设计,文档 可以同时拥有草稿版和已发布版。
- 内容 API 的默认行为是返回已发布的数据,例如
PUT /category/:id可用于更新文档的草稿版本并将其发布。 - REST API 响应返回已发布的版本,因此使用
id将会尝试使用其已发布版本的唯一标识符来更新组件或动态区域的草稿版本,这是不可能的。 - 尝试部分更新组件将导致以下错误:
Some of the provided components in component are not related to the entity。
-
此重大更改仅影响 REST API,而不影响文档服务 API,因为文档服务 API 默认返回文档的草稿版本。这也 使得在内容管理器中部分更新组件或动态区域成为可能。
手动操作
🌐 Manual procedure
更新你的自定义代码以在使用 REST API 时发送完整组件进行更新。
🌐 Update your custom code to send the full component to update when using the REST API.