组件和动态区域不返回 id
¥Components and dynamic zones do not return an id
在 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 中
¥In Strapi v4
在 Strapi v4 中,你可以通过传递其组件 id
来部分更新组件。
¥In Strapi v4, you can partially update a component by passing its component id
.
在 Strapi 5 中
¥In 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
:¥In Strapi v4, you could do the following send requests that would return a component's
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
字段。¥So you could specify the component
id
to update thevalue
field.在 Strapi 5 中:
¥In Strapi 5:
起草并发布 功能已重新设计,文档 可以同时拥有草稿和已发布版本。
¥The Draft & Publish feature has been reworked and documents can have both a draft and a published version.
Content API 的默认行为是返回已发布的数据,例如
PUT /category/:id
可用于更新文档的草稿版本并发布它。¥The default behaviour of the Content API is to return published data, for instance
PUT /category/:id
can be used to update the draft version of a document and publish it.REST API 响应返回已发布的版本,因此使用
id
将尝试使用已发布版本的唯一标识符来更新组件或动态区域的草稿版本,这是不可能的。¥The REST API response returns the published version, so using the
id
would resort to trying to update the draft version of a component or dynamic zone with the unique identifier of its published version, which is not possible.尝试部分更新组件将导致以下错误:
Some of the provided components in component are not related to the entity
。¥Trying to partially update a component will result in the following error:
Some of the provided components in component are not related to the entity
.
此重大更改仅影响 REST API,而不影响 文档服务 API,因为文档服务 API 默认返回文档的草稿版本。这也使得可以部分更新内容管理器中的组件或动态区域。
¥This breaking change only affects the REST API, not the Document Service API, because the Document Service API returns the draft version of a document by default. This also makes it possible to partially update a component or dynamic zone in the Content Manager.
手动程序
¥Manual procedure
更新你的自定义代码以在使用 REST API 时发送完整组件进行更新。
¥Update your custom code to send the full component to update when using the REST API.