我从yii开始,在尝试使用条件过滤CActiveDataProvider时遇到了一些麻烦.
这是我的数据库模型:
Table Columns
Project [id,name,status]
userToProject [user_id,project_id,role]
User [id,....]
我希望索引操作能够显示status = finished或用户当前分配给该项目的所有项目.
$criteria=array(
'order'=>'status desc','with'=>array(
'userToProject','userToProject.user'=>array('alias'=>'user')),);
$criteria['condition']='status=='.Project::STATUS_FINISHED;
$criteria['condition'].=' OR user.id = 6';
$dataProvider=new CActiveDataProvider('Project',array(
'criteria'=>$criteria,));
$this->render('index',array(
'dataProvider'=>$dataProvider,));
但它引发了一个异常,称未知列’user.id.我错过了什么?谢谢
Column not found: 1054
Unknown column 'users.user_id' in 'where clause'. The sql statement executed was:
SELECT `t`.`id` AS `t0_c0`,`t`.`name` AS `t0_c1`,`t`.`description` AS `t0_c2`,`t`.`status` AS `t0_c3`,`t`.`creation_date` AS `t0_c4` FROM `pgp_project` `t` WHERE
(status=4 OR users.user_id=6) ORDER BY status desc LIMIT 10
最佳答案
试试这个
原文链接:https://www.f2er.com/mysql/433885.html$criteria=new CDbCriteria(array(
'order'=>'status desc','with' => array('userToProject'=>array('alias'=>'user')),'condition'=>'status='.Project::STATUS_FINISHED.' OR user.id = 6',));
$dataProvider=new CActiveDataProvider('Project',array(
'criteria'=>$criteria,));
$this->render('index',array(
'dataProvider'=>$dataProvider,));