I have 2 models - AdRates and AdTypes. The relationship between them is Adrates has many Adtypes and Adtypes has one AdRates. In my relations definition in AdRates model, I have defined the relationship as:
public function relations()
'adtypes'=>array(self::HAS_MANY, 'AdTypes', 'adtype_id')
What I want to do is in the view file for AdRates, instead of displaying just the foreign key adtype_id, I want to display the description. So I defined the attributes in the view file as the following:
Thank you so much for your suggestions. I tested each one and here are the results:
Testing using without quotations at all, i.e.
‘value’ => $data->adtypes->description,
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘adtypes.adtype_id’ in ‘where clause’. The SQL statement executed was: SELECT adtypes.id AS t1_c0, adtypes.description AS t1_c1 FROM tbl_adtypesadtypes WHERE (adtypes.adtype_id=:ypl0)
Second test using dot notation, i.e.
This did not create a fatal error but the resulting display was:
Num Issues 2
So back to the beginning. What could be the problem? Did I define the relations incorrectly? Somehow the linkage between two tables does not seem to be recognized by Yii but I can’t figure out what I did wrong.
There really isn’t much here. It is just a simple one to many relationship.
does AdTypes table has adtype_id column? when you define HAS_MANY relation the referred model should have such column that points to AdRates primary key. if the relation is in different way - use BELONGS_TO relation type and then specified adtype_id columnt i AdRates should point to AdTypes primary key.