Yii CDbCriteria中的代码错误在哪里?

时间:2016-05-20 13:37:27

标签: php yii

当我使用此代码时:

$criteria = new CDbCriteria;
$criteria->addColumnCondition(array('paid'=>0, 'confirmed'=>0));
$criteria->addCondition('UNIX_TIMESTAMP() > (date + users.limited_pay_time * 3600)');
$orders = Orders::model()->findAll($criteria);

返回此错误。

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.limited_pay_time' in 'where clause'. The SQL statement executed was: SELECT * FROM `orders` `t` WHERE (paid=:ycp0 AND confirmed=:ycp1) AND (UNIX_TIMESTAMP() > (date + users.limited_pay_time * 3600)) 

1 个答案:

答案 0 :(得分:0)

这是发送到服务器的SQL:

SELECT * 
FROM `orders` `t` 
WHERE 
(paid=:ycp0 AND confirmed=:ycp1) 
AND (UNIX_TIMESTAMP() > (date + users.limited_pay_time * 3600)) 

您只是从订单中选择,而不是从用户中选择,因此您无法使用users.*字段,因为它们不会被查询!

你想要的是首先加入你的users表,这样你实际上就可以获得该表了。我不是Yii的专家,但不应该很难添加你所拥有的那些CDbCriteria的联接。例如,见:

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#join-detail