我想在 yii 中编写以下查询:
SELECT * FROM tbl_leaves as tl,tbl_users_master as um
WHERE tl.user_id = um.user_id AND YEAR(tl.leave_from_date) = YEAR(NOW())
我试图在 yii 中编写上述查询,如下所示:
$dataProvider=new CActiveDataProvider('Leaves', array(
'criteria'=>array(
'with'=>'user',
'together'=>true,
'condition'=>'user.user_id=:user_id AND YEAR(leaves.leave_from_date)= YEAR(NOW())',
'params'=>array(':user_id'=>$this->loadModel(Yii::app()->user->getId())->user_id),
),
));
$this->render('admin',array('model'=>$this->loadModel(Yii::app()->user->getId()),
'dataProvider'=>$dataProvider,
));
但它抛出了以下错误:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]:
Column not found: 1054 Unknown column 'leaves.leave_from_date' in 'where clause'.
执行的 SQL 语句是:
SELECT COUNT(DISTINCT `t`.`leave_id`) FROM `tbl_leaves` `t`
LEFT OUTER JOIN `tbl_users_master` `user` ON (`t`.`user_id`=`user`.`user_id`)
WHERE (user.user_id=:user_id AND YEAR(leaves.leave_from_date) = YEAR(NOW()))
我是 yii 新手,请帮助我如何在 yii 中编写上述查询。