Realm querying with two conditions at the same time

Viewed 5379

How would I query a structure like this:

public class Animal extends RealmObject { 
    RealmList<Bird> birds;
}


public class Bird extends RealmObject { 
    int type;
    RealmList<RealmInteger> species;
}

RealmInteger is an object with an int value

I want to find all Animal objects that have Bird which has a species of value 3 AND that Bird is of type 2

I tried this but it keeps ignoring the type:

realm.where(Animal.class)
    .equalTo("birds.type", 2)
    .equalTo("birds.species.value", 3)
    .findAll();

My guess is it finds a match with value but doesn't check the type field at the same time. I need a way of doing .equalTo("birds.species.value", 3) to check only Birds of type 2?

Update: Tried the @EpicPandaForce answer below, it is also returning this Animal with the data:

"birds": [
     {
        "species": [3, 15, 26],
        "type": 1
     },
     {
        "species": [],
        "type": 2,
     }
]

Because this Animal does not have a species value of 3 (it's empty) of type 2, it should NOT return it. Yet it does.

2 Answers
Related