Elias Andualem
Elias Andualem

Reputation: 366

how to convert RealmList<T> to RealmResults<T>

I am working on realm database and want to convert RealmList to RealmResults. The realmlist is attribute of realm object.

Upvotes: 0

Views: 250

Answers (2)

EpicPandaForce
EpicPandaForce

Reputation: 81539

It's very simple:

RealmResults<T> results = realmList.where().findAll();

Please note that this only works on managed RealmList.

Upvotes: 1

Maelig
Maelig

Reputation: 2096

Simple use query on your list :

class MyObject extends RealmObject {

    RealmList<MySubObject> subObjects;
}

...

myObject.subObjects.where().findAll(); //returns a RealmResults

//you can query your list like
myObject.subObjects
     .where()
     .equalTo("status", "done")
     .findAll(); //you can use sort, findFirst etc

Upvotes: 0

Related Questions