As we used total as a virtual field here, you can create a more similar one in the same model as:
public function index() { $checklist = TableRegistry::get('Checklists'); $query = $checklist->find() ->where('Checklists.is_deleted = 0') ->contain([ 'ChecklistTitles' => function($q) { return $q -> select([ 'ChecklistTitles.title', 'ChecklistTitles.checklist_id' ]); }, 'ChecklistTypes' => function($w){ return $w->select(['ChecklistTypes.type']); }, 'AssignedChecklists' => function($e){ $e->select([ 'AssignedChecklists.checklist_id', 'completed' => $e->func() ->count('AssignedChecklists.checklist_id'), ]) ->group(['AssignedChecklists.checklist_id']) ->where(['AssignedChecklists.is_deleted = 0 AND AssignedChecklists.checklist_status = 2']); return $e; } ]);
As I calculated completed here, I want to calculate canceled with another, where is the condition, what will be the syntax for it in cakephp3?
source share