Apro un nuovo topic visto che non ha relazione col problema della combo.
Sono sempre con quelle due tabelle, User e Language, dove User.languageId punta a Language
questa è la relation che c’è dentro il model di User
public function relations()
{
return array(
'languageObj' => array(self::BELONGS_TO, 'Language', 'languageId'),
);
}
La View.php è questa (si noti ‘languageObj.name’):
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'username',
'realname',
'email',
'companyId',
'languageObj.name'
'registrationDate',
'registrationUserId',
'isActive',
'isNotified',
'defaultModulesId',
),
)); ?>
Quando cerco di usare il l’action /View, passandogli un id, oppure anche solo il metodo /Index, ottengo questo:
CDbCommand ha riportato un errore nell’esecuzione della query SQL: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘languageObj.’ in ‘where clause’.
The SQL statement executed was:
SELECT languageObj
.id
AS t1_c0
, languageObj
.shortCode
AS t1_c1
, languageObj
.code
AS t1_c2
, languageObj
.name
AS t1_c3
, languageObj
.isDefault
AS t1_c4
FROM tbl_languages
languageObj
WHERE (languageObj
.``=:ypl0)
Questa volta cosa ho sbagliato !?
Aggiungo un dettaglio: l’errore è in
yii/framework/web/helpers/CHtml.php(1809)
dove c’è questo
1804 public static function value($model,$attribute,$defaultValue=null)
1805 {
1806 foreach(explode('.',$attribute) as $name)
1807 {
1808 if(is_object($model))
1809 $model=$model->$name;
1810 else if(is_array($model) && isset($model[$name]))
1811 $model=$model[$name];
1812 else
1813 return $defaultValue;
1814 }
1815 return $model;
1816 }