Dart ObjectBox nested query not working as expected

597 views Asked by At

I have the ObjectBox database and it is working pretty well. But nested queries not working as expected

List<Channel> _channels({required String lang}) {
    final queryBuilder = _channelBox().query();
    queryBuilder.linkMany(
        Channel_.category, ChannelCategory_.lang.equals(lang));
    queryBuilder.linkMany(Channel_.name, ChannelName_.lang.equals(lang));
    final query = queryBuilder.build();
    final result = query.find();
    query.close();
    //
    return result;
  }

This query returns all languages although the filter.

A unit test to demonstrate this

test("Channels for lang should have one language only", () {
    DB.languages.forEach((lang) async {
      (await db.channels(lang: "ar").first).forEach((channel) {
        channel.category.forEach((cate) {
          expect(cate.lang, "ar");
        });
        channel.name.forEach((name) {
          expect(name.lang, "ar");
        });
      });
    });
  });

here is how I defined my entities

@Entity()
class Channel {
  @Id()
  int id = 0;
  String url;
  ToMany<ChannelName> name = ToMany();
  ToMany<ChannelCategory> category = ToMany();
  bool isFavorite = false;    
}

@Entity()
class ChannelName {
  @Id()
  int id = 0;
  String name;
  String letter;
  String lang;
  @Backlink()
  final ToMany<Channel> channel = ToMany();
}

@Entity()
class ChannelCategory {
  @Id()
  int id = 0;
  String name;
  String lang;
  @Backlink()
  final ToMany<Channel> channel = ToMany();
}
0

There are 0 answers