问题描述
我正在使用 Symfony5
和 ApiPlatform
我正在尝试通过他们的 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 (将#修改为@)