Filtering on array field

#1

What is the behavior of fetch for this kind of filter:

MyType.fetch({filter: “myArray == ‘A’”}); ?

Does it return objects where ALL elements of myArray are equal to ‘A’ or ANY of the elements of myArray are equal to ‘A’.

I do not see any function like all() or any().

I know the intersects function. My understanding is that filter: “intersects(myArray, [‘A’])” will check if any elements of myArray contains ‘A’

0 Likes

#2

The call you mentioned is returning all the MyType instances having myArray containing at least one “A” element. So it is the equivalent of an any() method.
To implement the all() method you can try a filter like this:
count(unique(myArray)) == 1 && myArray =='A'

0 Likes