api-platform / api-platform/core

Probleme with DateFilter and ExistsFIlter on the same field

Open
#7,993 0 comments 0 reactions 0 assignees View on GitHub
filters
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 5h
Merged PRs (30d)
48

Description

Hi team,

First, thank you again for make my life easier with api-platform !

I've got an issue when i put a DateFIlter and an ExistsFilter on the same property.

The property :
```
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"get", "post", "put"})
*/
private $started;
```

The date filter :

```
@ApiFilter(DateFilter::class,
* properties={
* "started": DateFilter::EXCLUDE_NULL,
* }
* )

```

The ExistsFilter :

```
* @ApiFilter(ExistsFilter::class, properties={"started"})
```

With this code, i make request on client-side with params : 'started[exists]' to 'false'. Should return data with started = null;
But the date filter stop the exists filter because of the 'EXCLUDE_NULL'. In fact, i resolve this issue by update the DateFIlter like this
```
* "started": DateFilter::INCLUDE_NULL_BEFORE,
```
The 'INCLUDE_NULL' resolve the issue, but i think it isn't a normal comportement.
The DateFIlter that exclud null value should not affect ExistsFilter, isn't it ?
Or do i miss somthing ?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.