Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I'm getting "'Aggregate operations can only be used on RLMArray properties'"?

Tags:

ios

realm

I have the following query on my Realm database

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

Unfortunately it's not working, I'm getting the following error

'Invalid predicate', reason: 'Aggregate operations can only be used on RLMArray properties'

presentation is an optional entity defined like this on Event class

public dynamic var presentation : Presentation?

speakers is a List<PresentationSpeakers> defined like this on presentation

public let speakers = List<PresentationSpeaker>()

My feeling is that ANY must operate directly over a collection but speakers is not a direct property of Event.

What's wrong with my query and how can I implement it correctly?

like image 218
Claudio Redi Avatar asked Dec 07 '15 03:12

Claudio Redi


Video Answer


1 Answers

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

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

The ANY is implicit for the speakers property because it is a nested keypath. To specify something other than ANY, you would use a modifier on speakers like this:

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

However, Realm doesn't support this kind of query yet.

For more information on predicates and which ones are support by Realm, see Realm's predicate cheat sheet: https://realm.io/news/nspredicate-cheatsheet/

like image 157
jpsim Avatar answered Nov 04 '22 01:11

jpsim