アクティブレコードを使用してYiiでMANY_MANY関係を設定しようとしています。Yii MANY_MANY関係を設定する
私は3つのテーブル
プロファイル を持って説明profile_id profile_description
カテゴリ CATEGORY_ID カテゴリ名
profile_category は
私のモデルは、プロフィールのカテゴリ、およびProfileCategoryある CATEGORY_IDを説明profile_id。
私はcategory_idを使用してクエリを実行しようとしています。これは、そのカテゴリに含まれるすべてのプロファイルをプルアップします。
これはカテゴリモデルの情報です。
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'profiles'=>array(
self::MANY_MANY,
'Profile',
'profile_category(category_id, profile_id)',
),
'profile_category'=>array(
self::HAS_MANY,
'ProfileCategory',
'category_id',
),
);
}
プロファイルモデル
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'categories'=>array(
self::MANY_MANY,
'Category',
'profile_category(profile_id, category_id)'
),
'profileCategory'=>array(
self::HAS_MANY,
'ProfileCategory',
'profile_id'
),
);
}
ProfileCategoryモデル
コントローラ
public function actionResults()
{
$category=$_POST['terms'];
$dataProvider=new CActiveDataProvider(
'Profile',
array(
'criteria'=>array(
'with'=>array('profile_category'),
'condition'=>'display=10 AND profile_category.category_id=1',
'order'=>'t.id DESC',
'together'=>true,
),
)
);
$this->render('results',array(
'dataProvider'=>$dataProvider,
));
}
ビュー
<div id=resultsleft>
<?php
foreach($dataProvider as $value)
{
echo $value->profile_id;
}
?>
</div>
どのような考えですか?ありがとうございました!このビューには何も表示されません。