Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm Query possible to use IN? [duplicate]

Tags:

android

realm

I have the following realm query but from reading the documentation I don't see a possibility to do an IN query.

I need to search for an id in a string or array containing that id. Is this possible?

Example code:

Realm realmThread = Realm.getInstance(visnetawrap.appModel);
RealmResults<PropertyObject> propResults = realmThread.where(PropertyObject.class).contains("propertyID", "(5,7,10)").findAll();
like image 272
Joe Ginley Avatar asked Jul 05 '15 04:07

Joe Ginley


1 Answers

I'm afraid I am pointing out the obvious, but you can chain ored equalTos.

RealmQuery<PropertyObject> query = realm.where(PropertyObject.class);
query.beginGroup();
for(int i = 0; i < propertyIDs.length - 1; i++) {
    query.equalTo("propertyID", propertyIDs[i]).or();
}

query.equalTo("propertyID", propertyIDs[propertyIDs.length - 1]).endGroup();
RealmResults<PropertyObject> propResults = query.findAll();
like image 115
Ahmed Khalaf Avatar answered Nov 15 '22 03:11

Ahmed Khalaf