Hello guys,
I’ve been reading a lot of topics about this, but none of them have answered my question.
I have two tables (well, 3 but 2 for the example).
-Countries
–countryId
–countryName
-Teams
–teamId
–teamCountry
teamCountry is related to countryId.
These are my relationships:
//Team relations
return array(
'players' => array(self::HAS_MANY, 'Players', 'playerTeam'),
'countries' => array(self::HAS_ONE, 'Countries', 'countryId'),
);
//Countries relations
return array(
'players' => array(self::HAS_MANY, 'Players', 'playerCountry'),
'teams' => array(self::HAS_MANY, 'Teams', 'teamCountry'),
);
And this is a part of my admin model:
//Teams admin
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'teams-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'teamId',
'teamName',
array('name'=>'teamCountry', 'value'=>'$data->countries->countryName'),
'teamRanking',
array(
'class'=>'CButtonColumn',
),
),
));
As you could see, I’m trying to list the country name assigned to each team, instead of its ID.
Instead of showing me the correct name (I have Portugal -id:1- assigned to every team) and it is showing me all the countries that exist.
For example, I have 3 teams: Team 1, Team 2, Team 3; all assigned to Portugal (id:1).
It will show me every row in the Countries table:
Team 1 - Portugal
Team 2 - Brasil
Team 3 - England
etc
Any suggestions?