gerbil
gerbil

Reputation: 913

Querying for an object in a list in 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:

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 :-)

Upvotes: 7

Views: 2037

Answers (1)

bdash
bdash

Reputation: 18308

You can express this as either:

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

or:

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

Upvotes: 9

Related Questions