The code below works fine but when I copied the whole cakephp3 project with the same DB I get the below error. Since the same code works elsewhere I am unsure on how to fix this. I am using latest Wamp64, win10. The rest of the cakephp3 project works fine. The other computer used wamp64 and win7.
A solution is there but this involves changing the DB settings and i preferred to change the code.
Error related to only_full_group_by when executing a query in MySql
Error: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #11 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'aptutori_test.Lessons.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
$options['fields'] = array('DISTINCT Student.* ','Guardian.* ');
$options['conditions'] = array('Lessons.tutor_id' => $tutorId,'Student.student_inactive'=>0,
'Lessons.lesson_date >='=> $currDate, 'Lessons.makeup_lesson' => 0,'Lessons.forefit' => 0);
$fields = [
'Student.first_name','Student.last_name','Student.id',"Student.address_street","Student.address_suburb","Student.address_postcode","Student.class_year",
"Guardian.id",'Guardian.guardian_first_name',"Guardian.guardian_last_name"
];
$query = $this->Lessons->find('all');
$students = $query->where($options['conditions'])->autoFields(true)
->select($fields)->distinct(["Student.id",'Guardian.id'])
->join($options['joins'])
;
$this->set( 'student',$students);