guness
guness

Reputation: 6616

In realm, how to query from a RealmList (Android)

Check out following classes:

class Person{
    int id;
    String name;
    RealmList<Mail> mails;
    ...
}

class Mail{
    int id;
    String content;
    ...
}

I have a Person object (ie: mPerson) and I am accessing all Mails of the Person object by mPerson.getMails(). Till here everything is cool.


Here is the question: Is there way to query over the returned list such as findAllSortedAsync()?

Upvotes: 3

Views: 13785

Answers (2)

Ashish Dwivedi
Ashish Dwivedi

Reputation: 8186

    RealmResults<Contact> contacts = mRealm.where(Contact.class).findAll();

    int size = contacts.size();
    for (int i = 0;i<size;i++){
        Contact contact = contacts.get(i);
        RealmList<EMail> eMails = contact.emails;
    }

Upvotes: 0

beeender
beeender

Reputation: 3565

Just use RealmList.where() to create a query. You can find document here

For example: RealmList<Mail> mails = person.getMails(); RealmResults<Mail> results = mails.where().equalTo("id", 1).findAllSortedAsync();

Upvotes: 11

Related Questions