微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ApiFilter 存在未正确过滤

如何解决ApiFilter 存在未正确过滤

我正在使用 Symfony5ApiPlatform

我正在尝试通过他们的 product 属性用户进行排序,该属性是指向 ManyToOne 实体的​​ Product 属性

为此,我实现了 User.PHP 如下:


/**
 * @ApiResource(
 *     attributes={
 *          "normalization_context"={"groups"={"user:read","user:list"}},*          "order"={"someotherfield.start": "ASC"}
 *     },*     collectionoperations={
 *          "get"={
 *              "mehtod"="GET",*              "security"="is_granted('ROLE_CLIENT') or is_granted('ROLE_SPECIALIST')",*              "normalization_context"={"groups"={"user:list"}},*          },*          "post"={
 *              "method"="POST",*              "security_post_denormalize"="is_granted('POST',object)",*              "denormalization_context"={"groups"={"Default","user:post"}},*              "validation_groups"={"user_post"}
 *          }
 *     },*     itemOperations={
 *          "get"={
 *              "method"="GET",*              "security"="is_granted('GET',*          "put"={
 *              "method"="PUT",*              "security"="is_granted('PUT',*              "denormalization_context"={"groups"={"user:put"}},*              "validation_groups"={"user_put"}
 *          },*          "delete"={
 *              "method"="DELETE",*              "security"="is_granted('ROLE_ADMIN')"
 *          }
 *     }
 * )
 * @ApiFilter(ExistsFilter::class,properties={"product"})
 * @Gedmo\SoftDeleteable(fieldName="deletedAt",timeAware=false,hardDelete=false)
 * @ORM\Entity(repositoryClass=UserRepository::class)
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     * @Groups({"user:read","user:list","user:read"})
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity=Product::class,inversedBy="users",cascade={"persist","remove"})
     * @Groups({"user:read","user:put","user:read"})
     */
    private $product;
}

现在使用此过滤器,我希望恢复数据库中唯一具有 product 对象的用户,但是当我到达路由时,我正在恢复所有用户

https://localhost:8443/users?exists[office]=true&page=1

我只有一个原因,Fixtures 在本次测试中是这样组织的。

有谁知道过滤器为什么会这样,以及我在实现它时必须以何种方式犯错?

感谢您的反馈!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。