Crash when filtering a collection : 'Invalid predicate', reason: 'Key paths that include a collection property must use aggregate operations'

I am unable to filter results using this query in swift.
I got this error: ‘Invalid predicate’, reason: ‘Key paths that include a collection property must use aggregate operations’

items = realm.objects(Inspection.self).where {
$0.property.owners.fullName.contains(“substring”, options: [.diacriticInsensitive,.caseInsensitive])
}

I am unable to find away to get all property with owner full name containing ‘substring’.
Do you have an idea how to achieve this?

Thanks

I don’t know your model setup so I had to guess at it and with that I get the same error.

The error is because you’re attempting to filter on an array which requires the use of ‘ANY’.

It may be more convenient to form your query with an NSPredicate filter like this

let items = realm.objects(Inspection.self ).filter("ANY property.owners.fullName CONTAINS[cd] 'Jay'")

Thanks Jay for your answer.
What would be the correct syntax in where closure (I have several clauses) ?

items = realm.objects(Inspection.self).where {
    $0.property.internal_reference.contains(searchString, options: [.diacriticInsensitive,.caseInsensitive]) ||
    $0.property.owners.fullName.contains(searchString, options: [.diacriticInsensitive,.caseInsensitive]) ||
    ...
}

Thanks!

Again, we don’t know what your models look like - that would be helpful as something like owners sounds like a List and internal_reference doesn’t, or maybe it is, we just don’t want to have to guess.

You are right.
owner is a List and internal_ref a String.
I finally get it working by creating an NSPredicate with format.

Thanks a lot for your help.