关系不存在的Strapi V4过滤器



我正在建立一个类似评论的系统,其中评论有一个与另一个评论相关的parent字段。我希望能够通过查找没有parent集的注释来查询顶级注释,但我无法在文档中看到任何方法来做到这一点。

我尝试了这个,但它看起来不像$null过滤器在连接上工作。


const posts = await strapi.entityService.findMany('api::post.post', {
filters: {
thread: {
id: {
$eq: entity[0].id,
}
},
parent: {
$null: true,
}
}
});

我得到错误:只有$ And, $or和$not可以被用作根级操作符。发现空美元。

我在Strapi文档中找不到任何关于这个的内容,但这似乎是一个非常标准的事情。

filters[relation_name][id][$null]=true
or
filters:{
relation_name:{
id:{
$null:true
}
}
}

这可以帮助我过滤掉关系为空或不存在的记录。

所以我找到了使用Strapi查询API而不是实体服务的解决方案:

const posts = await strapi.db.query('api::post.post').findMany({
where: {
thread: entity[0].id,
parent: null
}
});