From 3e888803afb4cc4f68f16969a483528fc0ec265f Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 9 Apr 2023 21:16:27 +0200 Subject: [PATCH] add doc about filterHandler --- docs/entities/query.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/entities/query.md b/docs/entities/query.md index 18e79d5..da3c794 100644 --- a/docs/entities/query.md +++ b/docs/entities/query.md @@ -114,6 +114,34 @@ $entities = $query->create() ->find(); ``` +In the context of a CRUD, filters are applied using [the method `useFilters`](https://gitnet.fr/murph/murph-core/src/branch/master/src/core/Repository/RepositoryQuery.php#L78-L99). +Integers, strings and booleans are automatically processed. Other types are passed to [the method `filterHandler`](https://gitnet.fr/murph/murph-core/src/branch/master/src/core/Repository/RepositoryQuery.php#L122-L124). + +You have to override it to manage them, example: + +```php-inline +// ... + +use App\Entity\Something; + +class MyEntityRepositoryQuery extends RepositoryQuery +{ + // ... + + public function filterHandler(string $name, $value): self + { + if ($name === 'something' && $value instanceof Something) { + $this + ->join('something', 's') + ->andWhere('s.id = :something') + ->setParameter('something', $value->getId()) + ; + } + } +} +``` + + ## Pager You can paginate entities (`Knp\Component\Pager\Pagination\PaginationInterface`):