简体   繁体   中英

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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM