Exists filter doesn't work on array field
API Platform version(s) affected: 2.6.6
Description
When using the ExistsFilter on an Entity that has a field of the type array:
#[ORM\Column(type: 'array', length: 255, nullable: true)]
The filter doesn't work, that's because the filter uses IS NULL to filter it out.
But when I checked the database directly the value for null is N;
That's because serialize(null) gives N;
How to reproduce
An entity that has a field with the type array and the field's value is NULL
Use the ExistsFilter on that field
Possible Solution
- Make the filter use something like
= N; - Or not serialize NULL to 'N;' (I prefer this approach)
If you agree or have a better solution I can work on a PR
Hello, just a small reminder.
I can work on this I just need to know what's the approach you want to take
Or not serialize NULL to 'N;' (I prefer this approach)
That would be a suggestion to doctrine/dbal repository, which I'm sure would reject because it's a breaking change.
But I've found this line (so maybe someday):
https://github.com/doctrine/dbal/blob/719663b15983278227669c8595151586a2ff3327/src/Types/ArrayType.php#L32
Thanks for the answer.
Do you think that there is a solution that can be implemented on API platform level or is it better to just wait for Doctrine to implement it?
Make the filter use something like = N;
Is this a possible solution?
I think yes, but we need some feedback from core maintainers :)
- create a custom filter (maybe by using the code of our ExistsFilter)
- if you think it should benefit to everyone, please contribute it
Note that we want to improve doctrine filters alltogether at some point. Also check https://github.com/soyuka/esql which may be of interest.