我从 yii 开始,尝试使用标准过滤 CActiveDataProvider 时遇到了一些麻烦。
这是我的数据库模型:
Table Columns
Project [id, name, status]
userToProject [user_id,project_id,role]
User [id , ....]
我希望index操作显示所有 status=finished 的项目或用户当前分配给该项目的位置。
因此为了测试目的对用户 ID 进行硬编码。这是我的代码:
$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,
));
但它会抛出一个异常,说Unknown column '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