Skip to content

Commit e1b49d7

Browse files
author
Tim59
committed
#601 - Add note for usage of multiple value search in Filters
1 parent bbc7ef5 commit e1b49d7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

core/filters.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ Case insensitivity may already be enforced at the database level depending on th
136136
used. If you are using MySQL, note that the commonly used `utf8_unicode_ci` collation (and its sibling `utf8mb4_unicode_ci`)
137137
are already case insensitive, as indicated by the `_ci` part in their names.
138138

139+
Note : Search filters with the exact strategy can have multiple values for a same property (in this case the condition will be similar to a SQL IN clause)
140+
141+
Syntax: `?property[]=foo&property[]=bar`
142+
139143
In the following example, we will see how to allow the filtering of a list of e-commerce offers:
140144

141145
```php
@@ -160,6 +164,7 @@ class Offer
160164

161165
`http://localhost:8000/api/offers?price=10` will return all offers with a price being exactly `10`.
162166
`http://localhost:8000/api/offers?name=shirt` will return all offers with a description containing the word "shirt".
167+
`http://localhost:8000/api/offers?name[]=shirt&name[]=sweat` will return all offers with a description containing the word "shirt" or containing the word "sweat".
163168

164169
Filters can be combined together: `http://localhost:8000/api/offers?price=10&name=shirt`
165170

@@ -680,7 +685,7 @@ final class RegexpFilter extends AbstractContextAwareFilter
680685
) {
681686
return;
682687
}
683-
688+
684689
$parameterName = $queryNameGenerator->generateParameterName($property); // Generate a unique parameter name to avoid collisions with other filters
685690
$queryBuilder
686691
->andWhere(sprintf('REGEXP(o.%s, :%s) = 1', $property, $parameterName))
@@ -1074,7 +1079,7 @@ class DummyCar
10741079
* @ApiFilter(SearchFilter::class, properties={"colors.prop": "ipartial"})
10751080
*/
10761081
private $colors;
1077-
1082+
10781083
// ...
10791084
}
10801085

0 commit comments

Comments
 (0)