在 Strapi 5 中按 id 排序不再能按时间顺序排序
页面摘要: 由于基于 uuid 的文档,在 Strapi 5 中按
id排序不再按时间顺序生效;请改用文档服务 API 的createdAt。
在 Strapi 5 中,由于 文档 使用 uuid,按 id 排序来按时间顺序排序已不再可能。
本页面是破坏性变更数据库的一部分,提供有关该破坏性变更的信息,以及从 Strapi v4 迁移到 Strapi 5 的附加说明。
代码迁移工具: entity-service-document-service
破坏性变更说明
在 Strapi v4 中
在 Strapi v4 中,使用实体服务 API,你可以执行以下操作来按时间顺序排序条目:
strapi.entityService.findMany('api::article.article', {
sort: 'id',
});
在 Strapi 5 中
在 Strapi 5 中,使用 文档服务 API 按时间顺序排序文档时,请使用 createdAt 字段:
strapi.documentService.findMany('api::article.article', {
sort: 'createdAt',
});
迁移
本节汇总了关于该破坏性变更的有用说明和操作步骤。
手动操作步骤
由于这将由 codemod 处理,应无需手动操作。