错误:使用SELECT AS时出现yb CDbCriteria错误

时间:2015-08-10 09:40:08

标签: select yii

    $criteria = new CDbCriteria;
    $criteria->alias = 'form';
    $criteria->select = "( to_char(form.created_at,'Mon') || '-' || extract(year from form.created_at) ) as monthyear";
    $criteria->group = "monthyear";
    $criteria->order = "monthyear DESC";

    $model = odkForm::model()->findAll($criteria);

为什么我的 $ model 会返回空? ......像这样,但不在其他表中

任何人都可以提供帮助吗?

1 个答案:

答案 0 :(得分:0)

我认为是空的,因为在你的模型中不存在属性monthyear。因此,您可以将AS 与模型中描述的字段名称一起使用。这里有一个小例子,我认为这必须正常。希望这能帮助你。

$criteria = new CDbCriteria;
$criteria->alias = 'form';
// because created_at exist in model
$criteria->select = "( to_char(form.created_at,'Mon') || '-' || extract(year from form.created_at) ) as created_at";
$criteria->group = "created_at";
$criteria->order = "created_at DESC";

$model = odkForm::model()->findAll($criteria);