相关疑难解决方法(0)

ActiveAndroid多对多的关系

我目前正在使用ActiveAndroid,过去几个小时一直试图让多对多的关系工作,但是我无法让它工作.我希望你能帮助我:

我有模特"学生"和"课程",学生可以有很多课程,课程有很多学生.基本上这就是我在模型"StudentCourse"中所拥有的:

 @Column(name = COURSE)
 public Course course;

 @Column(name = STUDENT)
 public Student student;

 public StudentCourse(Student student, Course course) {
 super();
 this.student = student;
 this.course = course;
 }
//
 public StudentCourse(){ }

 public List<Course> courses(){
 return getMany(Course.class, "StudentCourse");
 }
 public List<Student> students(){
 return getMany(Student.class, "StudentCourse");
 }
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试做的是"课程X中的所有学生",使用以下代码:

((Student) new Select().from(StudentCourse.class).where("course = ?",selectedCourse.getId()).executeSingle()).students();
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

java.lang.ClassCastException:com.papinotas.models.StudentCourse无法强制转换为com.papinotas.models.Student

如果我将(学生)的演员表更改为(StudentCourse),我会收到以下错误:

android.database.sqlite.SQLiteException:没有这样的专栏:students.StudentCourse(代码1):,同时编译:SELECT*FROM学生WHERE students.StudentCourse = 1

我的主要目标是希望在一个查询中实现这一点.任何帮助将不胜感激.提前致谢!

PS:我已经看过几乎所有我能找到的东西:活跃的Android多对多关系https://github.com/pardom/ActiveAndroid/issues/46

java sql sqlite android activeandroid

7
推荐指数
1
解决办法
4359
查看次数

标签 统计

activeandroid ×1

android ×1

java ×1

sql ×1

sqlite ×1