# 组件和动态区域不会返回ID

> Source: https://strapi.nodejs.cn/cms/migration/v4-to-v5/breaking-changes/components-and-dynamic-zones-do-not-return-id

🌐 Components and dynamic zones do not return an `id`

在 Strapi 5 中，组件和动态区域在 REST API 响应中不再返回 `id`，这阻止了部分更新，并要求必须发送完整的组件对象。

🌐 In Strapi 5, components and dynamic zones no longer return an `id` in 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.

此页面是[重大更改数据库](/cms/migration/v4-to-v5/breaking-changes)的一部分，提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。

🌐 This page is part of the [breaking changes database](/cms/migration/v4-to-v5/breaking-changes) and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

- Is this breaking change affecting plugins? Yes
- Is this breaking change automatically handled by a codemod? No

## 重大变更描述 {#breaking-change-description}

🌐 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}

🌐 Migration

本节重新组合了有关引入的重大更改的有用说明和程序。

🌐 This section regroups useful notes and procedures about the introduced breaking change.

### 注意 {#notes}

🌐 Notes

* 在 Strapi v4 中，你可以执行以下操作来发送请求，这些请求将返回组件的 `id`：

  ```tsx
  // 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 中：
  * [草稿 & 发布](/cms/features/draft-and-publish) 功能已被重新设计，文档  可以同时拥有草稿版和已发布版。
  * 内容 API 的默认行为是返回已发布的数据，例如 `PUT /category/:id` 可用于更新文档的草稿版本并将其发布。
  * REST API 响应返回已发布的版本，因此使用 `id` 将会尝试使用其已发布版本的唯一标识符来更新组件或动态区域的草稿版本，这是不可能的。
  * 尝试部分更新组件将导致以下错误：`Some of the provided components in component are not related to the entity`。
* 此重大更改仅影响 REST API，而不影响[文档服务 API](/cms/api/document-service)，因为文档服务 API 默认返回文档的草稿版本。这也使得在内容管理器中部分更新组件或动态区域成为可能。

### 手动操作 {#manual-procedure}

🌐 Manual procedure

更新你的自定义代码以在使用 REST API 时发送完整组件进行更新。

🌐 Update your custom code to send the full component to update when using the REST API.
