Multiple columns in relation table


I’ve got a relation for my players model like this.

'team' => array(self::MANY_MANY, 'Team', '{{teams_players}}(team_id, player_id)', 'order'=>'leave_time ASC'),

Where I’m using a relational table to link each player with many teams, the teams_players table look like this.

team_id     int(11)

player_id   int(11)

join_time   int(11)

leave_time  int(11)

status      int(1)

Atm it works fine, the relation part, I get all the teams that the player has a been part of, sorted by the leave_time. The issue is, that I would like to be able to get the join_time, leave_time and the status from the relation table together with each team data.

How should I go about doing that?


See this section of the guide.

Something like this

class Player extends CActiveRecord



   public function relations()


       return array(







$data = Player::model()->findAll();

foreach ($data->tp as $tp)


  echo $tp->join_time;

  echo $tp->teams->some_attribute;