I'm currently using ActiveAndroid and trying to get many-to-many relationships to work in the last few hours, however I just can't get it to work. Hope you can help me:
I have the Student and Course models, a student can have many courses, and the course has many students. This is basically what I have in the StudentCourse model:
@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"); }
Now I'm trying to do "all students in X course" with the following code:
((Student) new Select().from(StudentCourse.class).where("course = ?",selectedCourse.getId()).executeSingle()).students();
However, I get the following error:
java.lang.ClassCastException: com.papinotas.models.StudentCourse cannot be attributed to com.papinotas.models.Student
If I change the (Student) cast to (StudentCourse), I get the following error:
android.database.sqlite.SQLiteException: there is no such column: students.StudentCourse (code 1): when compiling: SELECT * FROM students WHERE students.StudentCourse = 1
My main goal is to hope to achieve this in only one request. Any help would be greatly appreciated. Thanks in advance!
PS: I already covered almost everything I could find: an active many-to-many relationship for Android and https://github.com/pardom/ActiveAndroid/issues/46
java android sql sqlite activeandroid
Waclock
source share