使用activeJDBC查找Many2Many的记录

时间:2017-08-21 22:04:31

标签: many-to-many activejdbc javalite

我有这些模型的注释:

uri

如何让所有学生都参加UID课程?

1 个答案:

答案 0 :(得分: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);

就是这样!