realm-java
realm-java copied to clipboard
How to get only the relations matching the where clause when using link queries?
Say I have two classes:
Foo extends ReamlObject {
RealmList<Bar> bars;
}
Bar extends RealmObject {
boolean active;
}
When I then make the query:
RealmResults<Foo> fooResults = realm.where(Foo.class).equalTo("bars.active", true).findAll();
It returns all Foos that have atleast one active Bar, but in the RealmList: bars all nonactive Bar object still resides.
How can I make a link query where this is not the case?
If I understand you correctly, you want to filter the bars list so it only contains those elements that match a certain query?
That is currently not possible, at least not as a one-liner. Instead you would have to do something like this:
RealmResults<Foo> fooResults = realm.where(Foo.class).equalTo("bars.active", true).findAll();
for (Foo foo : fooResults) {
RealmResult<Bar> activeBars = foo.getBars().where().equalTo("active", true);
// ...
}
I hope it makes sense?
@cornflakes I assume your question was answered, please reopen if that was not the case.