I have an aplication that uses three tables:
Company - Fields:
id
name
DocType - Fields:
id
name
Documents - Fields:
id
year
id_company - foreign key Company->id
id_doctype - foreign key DocType->id
The models, views and controllers were generated with the fullmodel and fullcrud options of gii with the gtc extension
The relations in the controllers are defined as follows:
Company
'documents' => array(self::HAS_MANY, 'Documents', 'id_company'),
'userCompanys' => array(self::HAS_MANY, 'UserCompany', 'id_company'),
DocType
'documents' => array(self::HAS_MANY, 'Documents', 'id_doctype'),
Documents
'idDoctype0' => array(self::BELONGS_TO, 'Doctype', 'id_doctype'),
'idCompany0' => array(self::BELONGS_TO, 'Company', 'id_company'),
After i create some companies, documents and doctypes the documents appear in the company view with the year and a link to related document item.
The code in the Company view that shows the related documents thatresult from the foreign key is:
<ul><?php foreach($model->documents as $foreignobj) {
printf('<li>%s</li>', CHtml::link($foreignobj->year, array('documents/view', 'id' => $foreignobj->id)));
} ?></ul>
I would like to change the view to show also the doctype name.
I tried using $foreignobj->id_company->name, $foreignobj->userCompanys->Name and $foreigobj->id_company[0]->name (the index 0 is just for testing) with no success.
What should i do ?
Thanks in advance