[SOLVED]diplay the value

I have a,

  • company table

  • countries table

I supplied the dropDownList of the _form view of the company crud with the

data of the countries table like this




<?php echo $form->dropDownList($model,'Country',CHtml::listData(Worldareascountries::model()->findAll($country),'CountryID','CountryName')); ?>



now, when i add a new company, the value being saved to the db is the CountryID that served as the key of the dropDownList menu of the _form view

these two tables got no relationship, the countries table is a stand alone table for the whole db

I added a foreign key to the companies table that references the countryID of the countries table

this is the companies table

and this one is the stand alone countries table

here’s what my current company _view file code looks like




	<b><?php echo CHtml::encode($data->getAttributeLabel('Country')); ?>:</b>

	<?php echo CHtml::encode($data->Country); ?>

	<br />



I also added a relationship at the model like this





'country' => array(self::HAS_ONE, 'Worldareascountries', 'Country')




now my problem is, how will I show the country name at the UI , if it’s the ID being save in db ?

am confused

problem solved: here’s what i did

  1. Drop the Country foreign key ( because I can’t rename the column if i won’t drop it first )

  2. after renaming the column, add the foreign key back to the new column name = CountryID

  3. I added this at the relations function array




'countryID' => array(self::BELONGS_TO, 'Worldareascountries', 'CountryID'),



and here’s the code at the _view file




<?php echo CHtml::encode($data->countryID->CountryName); ?>