Strapi V4 过滤器,其中关系不存在

Tho*_*ant 4 node.js strapi

我正在建立一个类似评论的系统,其中评论有一个parent与另一个评论相关的字段。我希望能够通过查找未设置的评论来查询顶级评论parent,但我在文档中看不到任何方法来执行此操作。

我尝试过这个,但过滤器似乎不适$null用于连接。


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

我收到错误:只有 $and、$or 和 $not 可以用作根级别运算符。发现$null。

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

小智 5

filters[relation_name][id][$null]=true
or
filters:{
  relation_name:{
    id:{
      $null:true
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

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