In Yii2 I’m trying to populate a GridView with a query using a join:
// In the User model i get players like this
public function getPlayers(){
$query = new Query();
$query->select('player.id, first_name, last_name, birthdate, nationality, address, telephone, height, weight, position')
->from('player')
->innerJoin('user_team', 'user_team.teamId = player.teamId')
->where(['user_team.userId' => $this->id]);
return $query;
}
//In the Player Model I try to retrieve and display players like this:
$players = $user->getPlayers();
$dataProvider = new ActiveDataProvider([
'query' => $players,
]);
return $this->render('@common/views/player/index', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
The grid displays the data OK, but the action column has wrong ids. They all contain the row number (0,1,2,3…) instead of the actual player.id that is displayed in the ID column.
What am I doing wrong?
thanks!