Answer the question
In order to leave comments, you need to log in
How to use Yii 2 GRID widget with two tables?
I have two tables `user` and `auth_assignment` (which store user roles).
GIi generator to do CRUD for table `user`.
The question is how do I bind the auth_assignment table to it?
I found one way
(the code that was)
$query = UserList::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query = (new \yii\db\ActiveQuery())
->select( ['id' => 'user.id', 'username' => 'user.username' , 'auth_assignment.item_name' ])
->from('user')
->leftJoin('auth_assignment', 'auth_assignment.user_id = user.id');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question