Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying for an object in a list in Realm

Tags:

swift

realm

I'm using Realm 2.0 (Swift). My model is composed of X and Y (classes). X has a property called list which is a Realm List of Y objects.

Let's assume I have an instance of a Y object, called y The query I'm looking for is:

  • What X items contains an object equal to y in it's list of Y objects?

If the list was just a list of strings, I assume this would be trivial as the query would be: realm.objects(X.self).filter("<string> IN list")

Thanks :-)

like image 917
gerbil Avatar asked Nov 11 '16 23:11

gerbil


1 Answers

You can express this as either:

realm.objects(X.self).filter("%@ IN list", y)

or:

realm.objects(X.self).filter("ANY list = %@", y)
like image 141
bdash Avatar answered Oct 23 '22 06:10

bdash