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