如何始终在api平台GET操作中始终根据特定字段值过滤集合? [英] How to always filter a collection on specific field value in api-platform GET operations?
本文介绍了如何始终在api平台GET操作中始终根据特定字段值过滤集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在GET操作中,我想从返回的集合中排除具有等于"true"的"archive"字段的实体.
In the GET operations, I'd like to exclude from the returning collections my entities that have an " archive" field that equals " true ".
我希望将其设置为/users或/companies等端点的默认值,并且我希望避免像/users?filter [archive] = true
那样手动添加URL过滤器
I'd like that to be the default for my endpoints like /users or /companies and i want to avoid to add an URL filter by hand like /users?filter[archive]=true
什么是最好的方法?
感谢您的帮助:)
推荐答案
我必须做类似的事情,我通过对集合应用DoctrineExtension来解决此问题,该集合将WHERE子句添加到QueryBuilder.
I had to do something like that, and I solved it by applying a DoctrineExtension to a Collection that will add the WHERE clause to the QueryBuilder.
如何?
查看全文