Skip to content

Commit 49a2270

Browse files
committed
This PR documents the new ExistFilter behavior proposed in the pull request api-platform/core#2243.
1 parent fadb5de commit 49a2270

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

core/configuration.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ api_platform:
8989
api_keys: []
9090

9191
collection:
92+
# The name of the query parameter to filter nullable results (with the ExistsFilter).
93+
notnull_parameter_name: 'exists'
94+
9295
# The default order of results.
9396
order: 'ASC'
9497

95-
# The name of the query parameter to order results.
98+
# The name of the query parameter to order results (with the OrderFilter).
9699
order_parameter_name: 'order'
97100

98101
pagination:

core/filters.md

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

367367
The exists filter allows you to select items based on nullable field value.
368368

369-
Syntax: `?property[exists]=<true|false|1|0>`
369+
Syntax: `?exists[property]=<true|false|1|0>`
370370

371371
Enable the filter:
372372

@@ -390,10 +390,22 @@ class Offer
390390
}
391391
```
392392

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

395395
It will return all offers where `transportFees` is not `null`.
396396

397+
#### Using a Custom NotNull Query Parameter Name
398+
399+
A conflict will occur if `exists` is also the name of a property with the search filter enabled.
400+
Luckily, the query parameter name to use is configurable:
401+
402+
```yaml
403+
# api/config/packages/api_platform.yaml
404+
api_platform:
405+
collection:
406+
notnull_parameter_name: 'notempty' # the URL query parameter to use is now "notempty"
407+
```
408+
397409
### Order Filter (Sorting)
398410

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

0 commit comments

Comments
 (0)