-
-
Notifications
You must be signed in to change notification settings - Fork 844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] include null values for date filter #669
Comments
According to https://github.com/api-platform/docs/blob/master/core/filters.md#managing-null-values, it should work. You only need one line (before or after dpeending of the order you want). Can you provide your entity mapping? |
If I choose 'include_null_after', I have the NULL values when I filter the date with the If I choose 'include_null_before, I have the NULL values when I filter the date with the I check the code and it works as expected. But it's not what I am trying to achieve. Regarding the entity mapping, I think it's irrelevant since it's not related. I include it anyway. namespace ApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
/**
* @ORM\Entity
* @ORM\Table(name="contact")
* @ApiResource(attributes={
* "filters"={
* "filter.contact_date"
* }
* })
*/
class Contact
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $birthDate;
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
public function setBirthDate(\DateTime $birthDate = null)
{
$this->birthDate = $birthDate;
}
public function getBirthDate()
{
return $this->birthDate;
}
} The filter configuration: filter.contact_date_filter:
parent: 'api_platform.doctrine.orm.date_filter'
arguments:
- birthDate: include_null_after
tags:
- { name: 'api_platform.filter', id: 'filter.contact_date' } What I would like to do instead is something like: filter.contact_date_filter:
parent: 'api_platform.doctrine.orm.date_filter'
arguments:
- birthDate: include_null_always
tags:
- { name: 'api_platform.filter', id: 'filter.contact_date' } or like: filter.contact_date_filter:
parent: 'api_platform.doctrine.orm.date_filter'
arguments:
- birthDate: [include_null_after, include_null_before]
tags:
- { name: 'api_platform.filter', id: 'filter.contact_date' } |
@aledeg Can you perhaps add a Behat test case for this? 😄 |
@aledeg I agree with @teohhanhui could you please add a test ? |
I'm trying to understand this... If you specify Or in other words: a NULL value cannot be both the smallest and the largest value at the same time. |
Sorry guys, I didn't have time to reply. The thing is I don't want to consider null values as the smallest or the biggest values. I want to see them all the time. I'll try to give an example of what I am trying to achieve. |
I understand what you're trying to do, but I'm not convinced that it makes logical sense. Though I'm not against adding this feature... |
I took Feature: Foo filter
Scenario: Get foo list filtered by dob
Given I add 'Content-Type' header equal to 'application/json'
When I send a "POST" request to "/foos" with body:
"""
{
"bar": "bar 1",
"dob": "2015-01-01"
}
"""
When I send a "POST" request to "/foos" with body:
"""
{
"bar": "bar 2",
"dob": "2016-01-01"
}
"""
When I send a "POST" request to "/foos" with body:
"""
{
"bar": "bar 3"
}
"""
When I send a "GET" request to "/foos"
Then the JSON node 'hydra:member' should have 3 elements
When I send a "GET" request to "/foos?dob[before]=2015-10-10"
Then the JSON node 'hydra:member' should have 2 elements
When I send a "GET" request to "/foos?dob[after]=2015-10-10"
Then the JSON node 'hydra:member' should have 2 elements I tried all available options for my date filter and my tests are failing for all options. It's normal regarding how the filter is generated. |
Yes, it is expected behaviour. You're welcome to send a Pull Request to add this option. Others might find it useful too... |
@aledeg do you want to add a PR ? |
Sure but I need to find some time to do it :) |
I've started to look into it. I have a question regarding the contributing process. I've read the documentation but it's no help. I've looked for the behat tests to add/modify regarding that issue but I couldn't find anything. Is there something to add in those tests or I just need to write unit tests ? |
@aledeg You need to update the existing behat tests by adding a new Scenario and maybe a new fields on one of the tests entity, this is all located in the Do you want to do it ? |
I'll try to find some time to do it. |
Hi @aledeg , do you finally find a solution? I'm trying to have NULL for my date but even with the filter I can't even have my null values.
I'm calling the url http://api.local:8785/employees/1. Any help? |
@coolfarmer Please use the #api-platform channel on Symfony Slack for support questions. Thank you! |
I would like to always include null values while searching for dates.
It seems impossible for now. Correct me if I am wrong.
I tried to set the same field with different values but as expected, only one is used.
Did I miss something?
The text was updated successfully, but these errors were encountered: