Chaining queries

I am trying to chain queries and only the first chain is taking effect with all the rest beng bypassed. My questions are, is this the right way to do or is there a better way? Secondly, if this is the right way, why are the other filters being bypassed.

RealmResults getViolations({
bool bookmarkedOnly = false,
int? matatuId,
int? saccoId,
String? violationType,
DateTime? filterFrom,
}) {
var query = _realm.all();
if (bookmarkedOnly) {
query.query(“isBookMarked == true”);
if (matatuId != null) {
return query.query(‘ == $matatuId’);
if (saccoId != null) {
query.query(“ == $saccoId”);
if (violationType != null) {
query.query(“type == $violationType”);
return query;

Not sure what language that is, but if it’s dart, the result of .query is a new results object that you need to assign to the variable. It won’t modify the existing results in place.

1 Like

My bad. I overlooked that.