我正在尝试按category_id
过滤gridview中的产品记录我有三张桌子
ProductMst(产品,名称)
CategoryMst(CATEGORY_ID,category_nme)
PromotedUserProduct(category_id,product_id)====>联结表
public function relations()
{
return array(
'categoryMsts' => array(self::MANY_MANY, 'CategoryMst', 'promoted_user_product(user_product_id, category_id)'),
);
}
$criteria=new CDbCriteria();
$categoryCondition=array();
if(isset($_GET['category_id']) && $_GET['category_id']!==""){
$categoryCondition=array('select'=>false,
'condition'=>'categoryMsts.category_id=1',
'joinType'=>'INNER JOIN ');
}
$criteria->with=array(
'categoryMsts'=>$categoryCondition);
$dataProvider=new CActiveDataProvider('UserProductDtl',array(
'pagination'=>array(
'pageSize'=>$pagesize,
),
'criteria'=>$criteria,
));
$this->render('index',
array('dataProvider'=>$dataProvider));
我无法过滤记录,任何人都可以帮助我吗?
答案 0 :(得分:0)
更改此
$categoryCondition=array(
'select'=>false,
'condition'=>'category_id=:category_id',
'params'=>['category_id'=>$_GET['category_id'],
'joinType'=>'INNER JOIN '
);