模型.php
// Declare $datetime_limit
public datetime_limit;
控制器.php
// datetime_limit should be the actual datetime + 5 days
$criteria->select="DATE_ADD(NOW(), INTERVAL 5 DAY) AS datetime_limit";
错误信息:
Active record "Users" is trying to select an invalid column "DATE_ADD(NOW()". Note, the column must exist in the table or be an expression with alias.
编辑1:
我想使用关系表(多对多)过滤带有条件的查找。所以datetime_limit
不能有关系events.datetime
。我怎样才能做到这一点?
$criteria->select=array("DATE_ADD(NOW(), INTERVAL 5 DAY) AS datetime_limit");
$criteria->with=array('events');
$criteria->having='datetime_limit!=`events`.`datetime`';
$models=Users::model()->findAll($criteria);