0

我有这些模型的注释:

@Many2Many(other = Course.class, join = "registrations", sourceFKName = "student_uid", targetFKName = "course_uid")
public class Student extends Model {
}

@Many2Many(other = Student.class, join = "registrations", sourceFKName = "course_uid", targetFKName = "student_uid")
public class Course extends Model {
}

如何让所有学生都属于课程 UID?

4

1 回答 1

2

首先,您不需要两次指定相同的注释。这将是一样的:

public class Student extends Model {}

@Many2Many(other = Student.class, join = "registrations", sourceFKName = "course_uid", targetFKName = "student_uid")
public class Course extends Model { }

其次,您的案例在此页面上进行了描述:http: //javalite.io/many_to_many_associations#select-related-objects

所以,你会:

Course course = Course.findById(id);
List<Student> students = course.getAll(Student.class);

就这些!

于 2017-08-22T16:32:06.143 回答