CDbCriteria addConditions where子句不明确

时间:2017-02-23 07:55:31

标签: php mysql yii

我想按日期过滤记录,所以我添加了

createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end']

根据我的标准,我得到:

CDbCommand failed to execute the SQL statement: 
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'createDate' in where clause is ambiguous

这是我的代码:

     $criteria=new CDbCriteria;
                $criteria->with = array(
                        'Contacts' => array('alias'=> 'Contacts', 'together' => true, ),
                        'Lisings' => array('alias'=> 'listings', 'together' => true, ),
                    );
     $criteria->addCondition('createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end']);

     $result = Model::model('Portfolio')->findAll($criteria);

修复此错误的任何提示?我也试过了portfolio.createDate,但它没有用。

由于

1 个答案:

答案 0 :(得分:0)

在Yii 1中,模型表别名为t,因此您应该使用:

$criteria->addCondition('t.createDate BETWEEN ' . $dateRange['start'] . ' AND ' . $dateRange['end']);