Why do I get "Aggregate operations can only be used for RLMArray properties"?

I have the following query in my Realm database

 realm.objects(Event) .filter("ANY presentation.speakers.lastName CONTAINS [c]%@", searchTerm) 

Unfortunately, it does not work, I get the following error

"Invalid predicate", reason: "Aggregate operations can only be used for RLMArray properties"

presentation is an optional object defined as in the Event class

 public dynamic var presentation : Presentation? 

speakers is a List<PresentationSpeakers> defined as in a presentation

 public let speakers = List<PresentationSpeaker>() 

I feel that ANY should work directly on the collection, but speakers not a direct property of Event .

What is wrong with my request and how can I implement it correctly?

+5
source share
1 answer

Since presentation is a one-to-one relationship, there is no need to write ANY in your query:

 realm.objects(Event) .filter("presentation.speakers.lastName CONTAINS [c]%@", searchTerm) 

ANY implicit for the speakers property because it is a nested key path. To specify something other than ANY , you should use the modifier on speakers as follows:

 realm.objects(Event) .filter("presentation.speakers[FIRST].lastName CONTAINS [c]%@", searchTerm) 

However, Realm does not yet support this request.

For more information about predicates and which of them are supported by Realm, see the Realm predicate predicate sheet: https://realm.io/news/nspredicate-cheatsheet/

+3
source

Source: https://habr.com/ru/post/1237537/


All Articles