Hello Gray,
I was trying to fetch the ForeignCollection but unfortunately getting null value. Please find the details below:
Class StudentDetails
{
@DatabaseField(generatedId = true, columnName = "student_id")
public int studentId;
@DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true)
public TeacherDetails teacher;
.....
}
--------------------------------------
class TeacherDetails
{
@DatabaseField(generatedId = true, columnName = "teacher_id")
public int teacherId;
@ForeignCollectionField(eager = true, maxEagerLevel = 2)
private ForeignCollection<StudentDetails> students;
public ForeignCollection<StudentDetails> getStudents(){
return this.students;
}
}
-----------------------------------------------------------------------------------------------
I have added the reference of TeacherDetails in StudentDetails class while inserting into the database and can see "teacher" field of "StudentDetails" is being populated with actual teacherId.
But, when I am trying to query a teacher along with it's associated students, the getStudents() is always sending "null". Code which I am using is below :
TeacherDetails tDetails = getHelper().getTeacherDao().queryForId(1);
ForeignCollection<StudentDetails> students = tDetails.getStudents(); // students is always set as null
Am I missing something ?
- Surojit