【问题标题】:Find records with Many2Many using activeJDBC使用 activeJDBC 通过 Many2Many 查找记录
【发布时间】:2017-08-21 22:04:31
【问题描述】:

我有这些模型的注释:

@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?

【问题讨论】:

    标签: many-to-many activejdbc javalite


    【解决方案1】:

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

    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);
    

    就是这样!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多