I have a List<String> ids
and I want all the FooRealmObject
s that have the ID field included in the ids
list.
I could iterate through the ids
list and query objects by ID, but I was hoping there is a one-liner for this, like :
realm.where(Foo.class).in("id", ids).findAll();
Any ideas?
Now realm already support the feature you want.
Added in Realm Java 1.2.0. (https://github.com/realm/realm-java/issues/841)
Now you can do exactly what you want:
realm.where(Foo.class).in("id", ids).findAll();
As Jeremy mentioned, querying with a list of parameters is not possible (for now), but his answer does not work at all.
This is the workaround I used:
List<String> ids = ...;
Realm realm = Realm.getInstance(mContext);
RealmQuery<Foo> query = realm.where(Foo.class);
for (int i = 0; i < ids.size() - 1; i++) {
query = query.equalTo("id", ids.get(i)).or();
}
query = query.equalTo("id", ids.get(ids.size() - 1));
RealmResults<Foo> foos = query.findAll();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With