ApiPlatform - 使用过滤器时 hydra:view 和 hydra:totalItems 不正确

问题描述

我已经在我的班级 ApiPlatform 上实现了一些过滤器 User


 * @ApiFilter(SearchFilter::class,properties={
 *     "type": "exact",*     "othervalue": "exact",*     "something": "exact"
 * })

那些正在工作并返回正确的值。

所以我的 user 路线现在是:

  • /users
  • /users?type=value

问题来自:

  • hydra:totalItems
  • hydra:view

对于 /users?type=value,我得到了以下结果,带有奇怪的分页 view

  "hydra:totalItems": 0,"hydra:view": {
    "@id": "/interventions?type=sometype","@type": "hydra:PartialCollectionView"
  },

对于包含超过 300 行的 /users分页完全消失了

无论我拨打哪条路线,我都会得到"hydra:totalItems": 0

两者的分页都将从经典的 view 对象修改,如下所示:

  "hydra:view": {
    "@id": "/users?page=1","@type": "hydra:PartialCollectionView","hydra:first": "/users?page=1","hydra:last": "/users?page=15","hydra:next": "/users?page=2"
  }

我发现这个 GitHub 问题似乎与我的问题有关,但对于 custom doctrine filters,通过提高过滤器的优先级,可以触发它在正确的时间:

https://github.com/api-platform/core/issues/1185

我认为这是一个很好的线索,但还没有找到为 filter 提供的 ApiPlatform 而不是自定义的实现它的方法

如果我发现任何东西,我会把我的回复在这里给任何可能感兴趣的人

有谁知道为什么 ApiPlatform 对实施了 filter 的实体会有这种行为?谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)