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
Make empty
and nempty
work for Array types
#18042
Comments
The mentioned alternative does not work well when filtering within a (for example) delete flow step, where it is about a lot of items. Of course, you can also do this via a script, but feels like unnecessarily complicated. What you can do, right within the filter (since function parameters are now possible):
Maybe an alternative approach for this ticket is to update documentation instead of updating "_empty"? |
@jekuer how did you make type check work for this? |
@MarvinXu , you mean before whether it's an array or not OR regarding the type of the array element? Regarding first: This is quite static in my setup. Not sure, but most probably you could also work with the "_or" operator. like nnull = false OR count = 0. This would fail if not given at all, null or an empty array. Regarding latter one: I don't 😆 |
@jekuer sorry, I mean Typescript error |
Good catch. I don't, because I use this only at the integrated Flow-Feature of Directus. In my app, I am filtering out empty arrays after fetching the data from the Directus backend. |
Discussed in #18039
Originally posted by soulseekah April 3, 2023
Summary
There is currently no way to check if an array is empty or not.
_empty
does not work as per #18028while
"_eq": []
is not supportedBasic Example
Create a flow, Read step that returns [] when nothing is found, Condition that checks
{"$last": {"_empty": true}}
or{"$last":{"_eq": []}}
. First option expects''
,false
ornull
. Second option errors out as unsupported operand.Motivation
Checking if an array is empty or not is a quite important and foundational construct to have available in any system.
Detailed Design
_empty
and_nempty
should treat an empty[]
as falsy, despite them being always truthy.Requirements List
Must Have:
_empty
checks forlength
of 0 on array typed values_nempty
checks forlength
of >= 1 on array typed valuesShould Have:
n/a
Could Have:
n/a
Won't Have:
n/a
Drawbacks
There are no known drawbacks to supporting arrays in
_empty
and_nempty
.Alternatives
Writing a custom script that checks
.length
is a usable approach, before applying a condition.Adoption Strategy
_empty
will start supporting arrays. A notice will be posted on the release notes to notify people of the possible breaking changeUnresolved Questions
n/a
The text was updated successfully, but these errors were encountered: