Android Realm一对多关系,查询

Android Realm one to many relationship, query

我有两个 classes:

public class Employee extends RealmObject {
    @PrimaryKey
    long id;
    String name
    Department department;

    //getters setters etc.
}

public class Department extends RealmObject {
    @PrimaryKey
    int id;
    String name;

    //getters setters etc.
}

是一对多的关系。一个部门可以有多个员工。我试图提出一些疑问。

realm.where(Employee.class).equalTo("department.name", "deptName").findAll()
realm.where(Department.class).equalTo("employee.name", "empName").findAll()

第一个正常,第二个出错:

无效查询:员工未提及 class。

如何使第二个工作?我是否必须在部门 class 中创建员工的 RealmList?

我想在此查询中获取所有具有指定名称的员工的部门。

领域 3.5.0+:

public class Employee extends RealmObject {
    @PrimaryKey
    long id;
    String name
    Department department;

    //getters setters etc.
}

public class Department extends RealmObject {
    @PrimaryKey
    int id;
    String name;

    @LinkingObjects("department")
    private final RealmResults<Employee> employees = null;
    //getters setters etc.
}
realm.where(Employee.class).equalTo("department.name", "deptName").findAll()
realm.where(Department.class).equalTo("employees.name", "empName").findAll()