From 9c18cc61c8f853c07defbb7735b28b54b9345e36 Mon Sep 17 00:00:00 2001 From: akosse Date: Tue, 4 Feb 2020 14:28:41 +0300 Subject: [PATCH] accesses user-card innerJoin --- .../modules/accesses/controllers/AccessesController.php | 9 ++------- backend/modules/card/models/UserCardSearch.php | 8 +++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/backend/modules/accesses/controllers/AccessesController.php b/backend/modules/accesses/controllers/AccessesController.php index e589286..70f69db 100755 --- a/backend/modules/accesses/controllers/AccessesController.php +++ b/backend/modules/accesses/controllers/AccessesController.php @@ -5,6 +5,7 @@ namespace app\modules\accesses\controllers; use backend\modules\card\models\UserCardSearch; use common\classes\Debug; use common\models\ProjectAccesses; +use common\models\UserCard; use common\models\UserCardAccesses; use Yii; use common\models\Accesses; @@ -52,17 +53,11 @@ class AccessesController extends Controller { $searchModel = new UserCardSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - -// $query = \common\models\UserCard::find()->select(['id_user', 'fio', 'email']); -// -// $provider = new ActiveDataProvider([ -// 'query' => $query, -// ]); + $dataProvider->query->innerJoin('user_card_accesses', 'user_card.id = user_card_accesses.user_card_id'); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, - //'provider' => $provider ]); } diff --git a/backend/modules/card/models/UserCardSearch.php b/backend/modules/card/models/UserCardSearch.php index 8b25788..2117709 100755 --- a/backend/modules/card/models/UserCardSearch.php +++ b/backend/modules/card/models/UserCardSearch.php @@ -46,11 +46,9 @@ class UserCardSearch extends UserCard public function search($params) { $query = UserCard::find(); - // add conditions that should always apply here - $query->where(['id'])->distinct(); - //try join 3 tables - $query->leftJoin('card_skill', 'card_skill.card_id=user_card.id'); - $query->leftJoin('skill', 'skill.id=card_skill.skill_id'); + $query->where(['id'])->distinct() + ->leftJoin('card_skill', 'card_skill.card_id=user_card.id') + ->leftJoin('skill', 'skill.id=card_skill.skill_id'); $dataProvider = new ActiveDataProvider([ 'query' => $query,