Home » Java » Realm java chain queries for child

Realm java chain queries for child

Posted by: admin June 30, 2018 Leave a comment

Questions:

Here’s the sample parents with children

Parent[0].Children[0].Name = Johnson
Parent[0].Children[0].Age = 16

Parent[0].Children[1].Name = Jessica
Parent[0].Children[1].Age = 17

Parent[1].Children[0].Name = Lawson
Parent[1].Children[0].Age = 17

Parent[1].Children[1].Name = Jessica
Parent[1].Children[1].Age = 19

I just wanted to get parent with a child name Jessica & age 17

When I tried

realm.where(Parent.class).beginGroup().equalTo("childrens.name","Jessica").equalTo("childrens.age","17").endGroup().findAll();

It returned both parent to me as 2nd parent has children aged 17 & named Jessica. How can I get only the 1st parent?

Answers: