Skip to main content

权限提供程序实例的 getWhere() 方法已被删除

¥The getWhere() method for permission provider instances has been removed

在 Strapi 5 中,权限提供程序实例的 getWhere() 方法已被删除,用户应首先获取提供程序值,然后对其进行过滤。

¥In Strapi 5, the getWhere() method for permission provider instances has been removed, and users should first get the provider values, then filter 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.

\🔌 此重大更改是否会影响插件?\
\🤖 此重大更改是否由 codemod 自动处理?\

重大更改描述

¥Breaking change description

在 Strapi v4 中

¥In Strapi v4

提供一个浏览器名称来代替默认名称, 表示停止打开浏览器。

¥Provider instances (action provider, condition provider, etc…) are built using a provider factory.

这些提供商有一个 getWhere 方法,允许你查询符合特定条件的提供商项目并返回它们。

¥Those providers have a getWhere method allowing you to query provider’s items that match certain conditions and return them.

查询是一个对象,其中键和值与提供程序条目匹配:

¥The query was an object where keys and values were matched with the provider entries:



const values = provider.getWhere({ foo: 42, bar: 'baz' });



在 Strapi 5 中

¥In Strapi 5

你需要采用更传统的方法,首先获取提供商值,然后使用自定义谓词对其进行过滤:

¥You need to adopt a more conventional approach by first getting the provider values, then filtering them using a custom predicate:



const values = provider.values().filter(value => value.foo === 42 && value.bar === 'baz');


迁移

¥Migration

手动程序

¥Manual procedure

如果使用 getWhere() 方法,用户需要手动更新其代码,使用以下示例作为指南:

¥Users need to manually update their code if using the getWhere() method, using the following example as a guide:

在 Strapi v4 中

¥In Strapi v4



const values = provider.getWhere({ foo: 42, bar: 'baz' });



在 Strapi 5 中

¥In Strapi 5



const values = provider.values().filter(


value => value.foo === 42 && value.bar === 'baz'
);