Request an object in a list in Realm

I am using Realm 2.0 (Swift). My model consists of Xand Y(classes). Xhas a property listthat is a list of objects of objects Y.

Suppose I have an instance of an object Ycalled the Y Request I'm looking for, this:

  • What elements of X contain an object equal Yin its list of objects Y?

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

Thank: -)

+4
source share
1 answer

You can express it as:

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

or

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

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


All Articles