Specify key for yii\grid\ActionColumn

Hello -

I have modified the default dataprovider to retrieve data from 2 tables but now I do not know how to update the key which is used in the gridview to create the action column.

Here is my data provider:




   $query = new Query();

   $dataProvider = new ActiveDataProvider([

       'query' => $query->select ('g.id as id, p.title, p.id as post_id')->from('game g, post p')->where('g.post_id = p.id')

      ]);



In the gridview I want the default action, view, udpate and delete to use the id of the game (g.id) but now it is taking the line number. I am pretty sure this is because the 2nd table post also has a column named id.

I figured it out, just need to specify the key in the ActiveDataProvider


 

$dataProvider = new ActiveDataProvider([

            'query' => $query->select ('g.id as id, p.title, p.id as post_id')->from('game g, post p')->where('g.post_id = p.id'),

            'key' => 'id',

           

           ]);