/** * @return \yii\db\ActiveQuery */ public function getResGroupsUsersRels() { return $this->hasMany(ResGroupsUsersRel::className(), ['gid' => 'id']); }
public function actionGetAllUserList($search = null, $id = null) { $out = ['more' => false]; $q = new \yii\db\Query(); if (!is_null($search)) { $q->select('usr.id, prf.name as text')->from(ResGroups::tableName() . ' rg')->leftJoin(ResGroupsUsersRel::tableName() . ' rgu', 'rgu.gid = rg.id')->leftJoin(ResUsers::tableName() . ' usr', 'usr.id=rgu.uid')->leftJoin(ResPartner::tableName() . ' prf', 'prf.id=usr.partner_id')->where('rg.name like :rgName')->addParams([':rgName' => 'All Sales User'])->andWhere('LOWER(prf.name) LIKE :search', [':search' => '%' . strtolower($search) . '%']); $users = $q->createCommand()->queryAll(); // var_dump($q->createCommand()->sql); $out['results'] = array_values($users); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => ResUsers::find()->where(['id' => $id])->with('partner')->one()->partner->name]; } else { $out['results'] = ['id' => 0, 'text' => 'No matching records found']; } echo \yii\helpers\Json::encode($out); }