$data['clients'] = DB::select(DB::expr(Model_Client::table().'.*, COUNT('.Model_Project::table().'.id) AS num_projects'))
->from(Model_Client::table())
->join(Model_Project::table(),'LEFT')
->on(Model_Client::table().'.id','=',Model_Project::table().'.client_id')
->where(Model_Client::table().'.account_id',$this->current_user->account_id)
->as_object('Model_Client')
->order_by('num_projects','asc')
->limit($pagination->per_page)
->offset($pagination->offset)
->execute()
->as_array();
It looks like you're new here. If you want to get involved, click one of these buttons!