I have a table "MEDICATION" which is joined with "GENERICS_MED_TRADENAMES" table. "GENERICS_MED_TRADENAMES" table contains drug form of medicine which is referred in LIST_OF_VALUES table. After getting the result set of MEDICATION from DataProvider
to show in ListView
, I want to access DRUG_FORM description stored in LIST_OF_VALUES table but using Yii Model relations. I tried following but it did not work:
'genMedStrnDrgform' => array(self::BELONGS_TO, 'GenericsMedTradenames', 'gen_med_strn_drgform_id'), -- This is okay, I can access the attributes
'drugForm' => array(self::BELONGS_TO, 'ListOfValues', 'genMedStrnDrgform.drug_form_id'), -- This does not work since it is nested. Yii thorws error.
To further explain what I want, I have also explained the same in form of SQL queries (Putting a snapshot because indentation is very difficult to present my question in a proper way):
I need to display DrugFrom description and tried the following in ListView file but both are not working: drugForm->group_display_val
"$data->genMedStrnDrgform->drugForm->group_display_val"
"$data->drugForm->group_display_val"
Place in Medication
:
'genMedStrnDrgform' => array(self::BELONGS_TO, 'GenericsMedTradenames', 'gen_med_strn_drgform_id')
Place in GenericsMedTradenames
'drugForm' => array(self::BELONGS_TO, 'ListOfValues', 'drug_form_id')
then do the query like this:
$posts=Medication::model()->findAll(array(
'with'=>array(
'genMedStrnDrgform',
'genMedStrnDrgform.drugForm'
)
));