Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm where not contains in Java

If I have an array of primitive values, how can I run a .not().contains() on a .where() from RealmResults ?

The code would hopefully look like this:

 results.where().not().contains("id", new int[] {1, 2, 3})

Or do I have to iterate over all of these results and pluck them out individually?

like image 406
tyler Avatar asked Jun 15 '16 21:06

tyler


2 Answers

You can try beginGroup and then not in to query against the Arrays

realm1.where(UserModel.class)..beginGroup().not().
                    in("key",Your Array)).endGroup().findAll();
like image 162
Raja Jawahar Avatar answered Nov 10 '22 03:11

Raja Jawahar


There is no such method to query against the arrays as of now . The second paramater of contains() requires a string so you cant pass int[] or int . Iterating over the result is the only option .

RealmQuery q = users.where();
for (int id : ids) {
q = q.notEqualsTo("id", id);
}
RealmResults<users> users = q.findAll();

You can use between() if you need to query against a range of value .

like image 37
randy Avatar answered Nov 10 '22 02:11

randy