Skip to content

Commit 9d3d5a5

Browse files
epourailalanpoulain
authored andcommitted
This PR documents the new ExistFilter behavior proposed in the pull request api-platform/core#2243. (#613)
1 parent 47ebcf9 commit 9d3d5a5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

core/configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ api_platform:
116116
api_keys: []
117117

118118
collection:
119+
# The name of the query parameter to filter nullable results (with the ExistsFilter).
120+
exists_parameter_name: 'exists'
121+
119122
# The default order of results.
120123
order: 'ASC'
121124

122-
# The name of the query parameter to order results.
125+
# The name of the query parameter to order results (with the OrderFilter).
123126
order_parameter_name: 'order'
124127

125128
pagination:

core/filters.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ You can filter offers by joining two values, for example: `/offers?price[gt]=12.
369369

370370
The exists filter allows you to select items based on nullable field value.
371371

372-
Syntax: `?property[exists]=<true|false|1|0>`
372+
Syntax: `?exists[property]=<true|false|1|0>`
373+
374+
Previous syntax (deprecated): `?property[exists]=<true|false|1|0>`
373375

374376
Enable the filter:
375377

@@ -393,10 +395,22 @@ class Offer
393395
}
394396
```
395397

396-
Given that the collection endpoint is `/offers`, you can filter offers on nullable field with the following query: `/offers?transportFees[exists]=true`.
398+
Given that the collection endpoint is `/offers`, you can filter offers on nullable field with the following query: `/offers?exists[transportFees]=true`.
397399

398400
It will return all offers where `transportFees` is not `null`.
399401

402+
#### Using a Custom Exists Query Parameter Name
403+
404+
A conflict will occur if `exists` is also the name of a property with the search filter enabled.
405+
Luckily, the query parameter name to use is configurable:
406+
407+
```yaml
408+
# api/config/packages/api_platform.yaml
409+
api_platform:
410+
collection:
411+
exists_parameter_name: 'not_null' # the URL query parameter to use is now "not_null"
412+
```
413+
400414
### Order Filter (Sorting)
401415

402416
The order filter allows to sort a collection against the given properties.

0 commit comments

Comments
 (0)