flutterdartobjectbox

Objectbox dart: How to filter objects within objects in ToOne Relation


Suppose I have code like this

@Entity()
class ObjectOne {
  int id;
  String code;
  String name;
  final objectTwo = ToOne<ObjectTwo>();
}

@Entity()
class ObjectTwo {
  int id;
  String code;
  String name;
  final objectThree = ToOne<ObjectThree>();
}

@Entity()
class ObjectThree {
  int id;
  String code;
  String name;
}

If you get the name value in the ObjectTwo class, you can use code like this

final objects = store.box<ObjectOne>().query()
  ..link(ObjectOne_.objectTwo, ObjectTwo_.name.equals("value"))
  ..build()

What if I want to retrieve the name value of class ObjectThree in class ObjectOne via class ObjectTwo ?

Thank youu...


Solution

  • Just add another link condition to the query builder returned by the first link condition:

        final builder = store.box<ObjectOne>().query();
        builder
            .link(ObjectOne_.objectTwo)
            .link(ObjectTwo_.objectThree, ObjectThree_.name.equals("value"));
        final query = builder.build();
    

    Source