I want to get my Jobs with associated Jobstasks, but from Jobstasks i want to get counted total1 - all tasks in job (thats works well), and (commented, ofcourse not working) total2 - counted finished tasks. Any idea?
$jobs = $this->Jobs->find('all')
->where(['Jobs.user_id' => $user_id])
->andWhere(['Jobs.start >' => new \DateTime('+6 days')])
->contain(['Jobgroups',
'Jobstasks' => function($q){
$q->select([
'JobsTasks.job_id',
'JobsTasks.finished',
'total1' => $q->func()->count('JobsTasks.job_id'),
//'total2' => $q->func()->where(['JobsTasks.finished' => true])->count()
])->group(['JobsTasks.id']);
return $q;
}
])
->order(['Jobs.start' => 'ASC']);
Thnx to you Arilia, your total2 works great :) change total1 is not necessary. Below is solution. And i have to change Grouping for correct data output.