Yii Framework Forum: Wrong Id In Gridview Action Column - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Wrong Id In Gridview Action Column Wrong id when using join in query

#1 User is offline   cloudeeo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 18-January 14

Posted 20 September 2014 - 04:13 PM

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!
0

#2 User is offline   fstegmeyer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 26-November 14

Posted 26 November 2014 - 08:01 AM

Hey,

since I'm facing the same situation right now, did you find a solution or a workaround for this?

thanks
0

#3 User is offline   Hashie 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 20-February 14

Posted 26 November 2014 - 08:24 AM

can you show your code from `@common/views/player/index`
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users