You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/filters.md
+225Lines changed: 225 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -661,6 +661,231 @@ class Offer
661
661
You can now enable this filter using URLs like `http://example.com/offers?regexp_email=^[FOO]`. This new filter will also
662
662
appear in Swagger and Hydra documentations.
663
663
664
+
### Using Doctrine Filters
665
+
666
+
Doctrine features [a filter system](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/filters.html) that allows the developer to add SQL to the conditional clauses of queries, regardless the place where the SQL is generated (e.g. from a DQL query, or by loading associated entities).
667
+
These are applied on collections and items, so are incredibly useful.
668
+
669
+
The following information, specific to Doctrine filters in Symfony, is based upon [a great article posted on Michaël Perrin's blog](http://blog.michaelperrin.fr/2014/12/05/doctrine-filters/).
670
+
671
+
Suppose we have a `User` entity and an `Order` entity related to the `User` one. A user should only see his orders and no others's ones.
It's key to set the priority higher than the `ApiPlatform\Core\EventListener\ReadListener`'s priority, as flagged in [this issue](https://github.com/api-platform/core/issues/1185), as otherwise the `PaginatorExtension` will ignore the Doctrine filter and return incorrect `totalItems` and `page` (first/last/next) data.
Done: Doctrine will automatically filter all "UserAware" entities!
888
+
664
889
### Overriding Extraction of Properties from the Request
665
890
666
891
You can change the way the filter parameters are extracted from the request. This can be done by overriding the `extractProperties(\Symfony\Component\HttpFoundation\Request $request)`
0 commit comments