ApiFilter Exists not filtering properly

I’m using Symfony5 and ApiPlatform

I’m trying to sort user through their product property which is a ManyToOne property pointing to the Product entity.

To do so I’ve implemented User.php as follow :


/**
 * @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', object)",
 *          },
 *          "put"={
 *              "method"="PUT",
 *              "security"="is_granted('PUT', object)",
 *              "denormalization_context"={"groups"={"user:put"}},
 *              "validation_groups"={"user_put"}
 *          },
 *          "delete"={
 *              "method"="DELETE",
 *              "security"="is_granted('ROLE_ADMIN')"
 *          }
 *     }
 * )
 * @ApiFilter(ExistsFilter::class, properties={"product"})
 * @GedmoSoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
 * @ORMEntity(repositoryClass=UserRepository::class)
 */
class User
{
    /**
     * @ORMId
     * @ORMGeneratedValue
     * @ORMColumn(type="integer")
     * @Groups({"user:read", "user:list", "user:read"})
     */
    private $id;

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

Now with this filter I was expecting to recover the only user with a product object in my db, but I’m recovering all of them when I hit the route :

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

I only have one cause the Fixtures are organized this way for this test.

Does anyone know why the filter act this way, and in what manner I must have made a mistake by trying to implement it ?

Thanks for your feedback !

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *