Closed jean-gui closed 3 years ago
When using it with "is not equal to", results don't include entries for which the
user
column is null, which is very counter-intuitive.
I'm not sure it's counter-intuitive. For me this is the behaviour of every Filter provided by Sonata. When you look for a value which is not equal to something, you still look for a value.
It's similar to the behaviour of SQL:
SELECT * from foo WHERE bar <> 'something'
Doesn't return the foo with a NULL bar value.
The change introduced by the issue #991 was kinda to use IS NULL
if you selected null
value specifically, instead of == NULL
which was always false or not filtering at all.
What you're asking would be a feature or a BC-break, it doesn't seems like a bug to me.
The confusing thing is that because of this behavior the total number of rows is different from the sum of "is equal to" and "is not equal to". At least that's confusing to my user and to me since I had to dig to understand what was going on.
If you think it's not a bug, could it at least be configurable? That would would also prevent the BC-break.
When you're looking for a boolean value which is not true
, you get the same result that when you're looking for a boolean which is false
. You don't get the null
value.
I'm pretty sure changing this behaviour would lead to someone saying that's confusing.
This is the same in your case but with multiple value. Let say there is 4 values, A, B, C, D. Not A = B + C + D.
When you use the DateFilter
and looking for a date which is not between yesterday and today, null
date are not return.
But there seems to be a custom NULL
operator:
public const CHOICES = [
DateOperatorType::TYPE_EQUAL => '=',
DateOperatorType::TYPE_GREATER_EQUAL => '>=',
DateOperatorType::TYPE_GREATER_THAN => '>',
DateOperatorType::TYPE_LESS_EQUAL => '<=',
DateOperatorType::TYPE_LESS_THAN => '<',
DateOperatorType::TYPE_NULL => 'NULL',
DateOperatorType::TYPE_NOT_NULL => 'NOT NULL',
];
This could be an idea...
Hi @jean-gui
I found https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/649/files https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/650/files
It seems like filters was starting to work like you wanted.
I looked again at the filter
null
values when using NOT_EQUAL
; maybe it should...NULL
operator.null
values when using NOT_EQUAL
.null
values when using NOT_EQUAL
.@sonata-project/contributors I think we should look for consistency. Does a negative operator should return null values or not ?
It currently weird that ModelFilter
does, but ModelAutocompleteFilter
doesn't.
Or that StringFilter
does but ChoiceFilter
or NumberFilter
doesn't.
Thanks @VincentLanglet for investigating this issue!
Do you want to make a PR @jean-gui ?
Unfortunately, I don't think I have enough time for that :-/
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Closing in favor of https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/1513
Environment
Sonata packages
Symfony packages
PHP version
Subject
I have several filters such as
When using it with "is not equal to", results don't include entries for which the
user
column is null, which is very counter-intuitive. I think that's somewhat related to https://github.com/sonata-project/SonataAdminBundle/issues/3569 and #991, although not exactly the same.I managed to fix this by replacing the line 107 of ModelAutocompleteFilter: before:
after:
But I don't know if that's the best way to fix it or if this will create other issues. I also don't know the code enough to assess that possibility and provide a usable MR.
Thanks, Jean-Gui