使用 activeJDBC 通过 Many2Many 查找记录
Find records with Many2Many using activeJDBC
我有这些模型的注释:
@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?
首先,您不需要指定相同的注解两次。这将同样有效:
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);
就这些!
我有这些模型的注释:
@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?
首先,您不需要指定相同的注解两次。这将同样有效:
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);
就这些!