Hi all,
I have an app tracking training courses for volunteers. There are a number of mandatory training courses that must be completed every two years, and I need to track completion/compliance on this requirement. Based on a classification, not all members need to complete all courses.
There is a Members table and a TrainingCourses table, and finally a MemberTrainingCourses that tracks the course a member completed along with completion date and expiry date so we know when the course needs to be re-sat.
Member has many MemberTrainingCourses
$this->hasMany('MemberTrainingCourses', [
'dependent' => true,
'foreignKey' => 'member_id'
]);
MemberTrainingCourse belong to Members and TrainingCourses
$this->belongsTo('Members', [
'foreignKey' => 'member_id',
'joinType' => 'INNER',
]);
$this->belongsTo('TrainingCourses', [
'foreignKey' => 'training_course_id',
'joinType' => 'INNER',
]);
I’ve created a report that gives me members and the courses they’ve done
$members = $this->Members->find()
->contain([
'MemberTrainingCourses' => [
'queryBuilder' => function($q) use($training_course_selected) {
return $q
->contain('TrainingCourses')
->where(['training_course_id' => $training_course_selected])
->order('date_of_expiry DESC')
->limit(1);
}]
]);
Because they resit every two years and there might be multiple entries per member, this will return all relevant members and their most recently completed course.
The report all works fine, however when I try to sort on course name or date_of_expiry I get
Column not found: 1054 Unknown column 'MemberTrainingCourses.date_of_expiry' in 'order clause'
I’m guessing this is because some Members returned have no relevant Training Courses (these are the people who need reminding/following up), and the associated record for this member is empty?
Everything else is working for me - just the sorting on the fields doesn’t.
Thanks in advance!