[英]fetch data using some condition in strapi
I am creating api using strapi.我正在使用 strapi 创建 api。 i have a situation, i want to fetch data
我有一个情况,我想获取数据
where audience_name like '%audienceName%' and created_by = 4;
其中audience_name like '%audienceName%' and created_by = 4;
below is my strapi code下面是我的strapi代码
findByName: async (ctx) => {
const audienceName = ctx.params.name;
return strapi.services.audience.find({
audience_name: { 'like' : audienceName},
created_by: ctx.state.user.id
});
},
but i am not able to get the data it is trowing internal server error as below.但我无法获得它正在引发内部服务器错误的数据,如下所示。
In your case you will have to use these two concepts:在您的情况下,您将不得不使用这两个概念:
contains
instead of %
contains
而不是%
的过滤器User
relation User
关系You will see, params you are trying to send are not in the right format.您会看到,您尝试发送的参数格式不正确。
Your code should look like this您的代码应如下所示
const data = await strapi.services.audience.find({
audience_name_contains: audienceName,
created_by: ctx.state.user.id
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.