向包含连接语句的活动记录查询添加限制的正确方法是什么?我已经有一个 activerecord 连接语句,它可以转换为正确的 SQL
static $belongs_to = array(
array('job_request')
);
$requests = $this->all(array(
'joins' => array('job_request'),
'conditions' => array('DATE(job_date) >= ? AND DATE(job_date) <= ? AND'
. ' user_id = ?', $start_date, $end_date, $userid))
);
这将转换为 SQL
SELECT `job_applications`.* FROM `job_applications` INNER JOIN `job_requests`
ON(`job_applications`.job_request_id = `job_requests`.id) WHERE
DATE(job_date) >= '2013-01-28' AND DATE(job_date) <= '2013-03-04'
AND user_id = '1'
但是如果我添加限制,则连接将从 SQL 查询中删除
$requests = $this->all(array(
'joins' => array('job_request'),
'conditions' => array('DATE(job_date) >= ? AND DATE(job_date) <= ? AND'
. ' user_id = ?', $start_date, $end_date, $userid)),
array('limit' => 200, 'offset' => 0)
);
生成
SELECT * FROM `job_applications` LIMIT 0,999999