我GoodsCats
模型與未來的關係:的Yii:動態變化模型關係類型與模型() - >與()
public function relations(){
return array(
'GoodsCatsContent' => array(self::HAS_MANY, 'GoodsCatsContent', 'parent_id'),
);
}
,現在我想找到所有GoodsCats
要素,但有一個孩子元素(具體language_id
):
$cats = GoodsCats::model()->with(
array(
'GoodsCatsContent'=>array(
'on'=>'languages_id = 1'
)
)
)->findAll();
並且其中每個elemt是recive陣列等GoodsCats.id=>GoodsCatsContent.name
:
CHtml::listData(cats, 'id', 'name')
但是現在我得到一個錯誤GoodsCats.name not defined
。 當我設置GoodsCats
關係爲self::HAS_ONE所有的作品都很好,但我無法改變整個項目。 它有可能以某種方式設置model()->with()使用未定義的關係類型,但一個特定的?
UPD我的模型規則:
GoodsCatsContent
:
public function rules()
{
return array(
array('parent_id', 'required'),
array('active', 'numerical', 'integerOnly'=>true),
array('parent_id', 'length', 'max'=>10),
array('name, seo_title, seo_keywords, seo_description', 'length', 'max'=>255),
array('short_content, content', 'safe'),
array('id, parent_id, active, name, short_content, content, seo_title, seo_keywords, seo_description', 'safe', 'on'=>'search'),
);
}
GoodsCats
:
public function rules()
{
return array(
array('active, prior', 'numerical', 'integerOnly'=>true),
array('photo', 'length', 'max'=>255),
array('id, photo, active, prior', 'safe', 'on'=>'search'),
);
}
你的模型是什麼樣的? – Jon
@Jon你是不是指每個模型的'rules()'或'search()'? –
我的意思是'rules()'。 – Jon