我有一个包含以下字段的课程实体
@Index
private @Load
Ref<Student> student;
然后学生实体拥有该字段
@Index
private String matric;
我想使用学生的matric编号加载所有课程实体已排序。
我尝试过使用&#34;。&#34;运算符来获取像这样的子字段
ofy().load().type(Course.class).filter("course", course).order("student.matric").list();
但是没有结果。
有可能这样做吗?怎么样?
答案 0 :(得分:3)
我不认为这可能是客观化的。我会让课程实现可比较:
File.query.order_by(File.title).limit(per_page).offset(page*page_size)
删除&#34;命令&#34; Objectify的一部分加载并使用Collections.sort()代替:
@Entity
public class Course implements Comparable<Course> {
.
.
.
@Override
public int compareTo(Course otherCourse) {
return this.getStudent().getMatric().compareTo(otherCourse.getStudent().getMatric());
}
}
答案 1 :(得分:1)
数据存储区中没有连接。如果要按学生属性查询课程,可能需要将数据反规范化为课程并将其编入索引。这意味着更改学生数据也需要更改课程。
暂且不说:这个数据模型很奇怪。你确定你在说什么课程不是真正的入学吗?