2017-08-21 5 views
0

Ich habe diese Anmerkungen für die Modelle:Suchen von Datensätzen mit Many2Many mit 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 { 
} 

Wie bekomme ich alle Schüler zu einem Kurs UID gehören?

Antwort

2

Zuerst müssen Sie die gleiche Anmerkung nicht zweimal angeben. Dies funktioniert genauso:

public class Student extends Model {} 

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

Zweitens Ihr Fall auf dieser Seite beschrieben wird: http://javalite.io/many_to_many_associations#select-related-objects

so, würden Sie:

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

Das ist alles!

Verwandte Themen