phpactiverecord加入限制

时间:2013-02-28 11:44:33

标签: join phpactiverecord

为包含连接语句的activerecord查询添加限制的正确方法是什么?我已经有一个activerecord join语句转换为正确的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

1 个答案:

答案 0 :(得分:0)

limit和offset属于第一个数组。

array('conditions'=>'...',
      'joins'=>'...',
      'limit'=>5',
      'offset'=>5
);

您的数组看起来像

 array('conditions'=>'...',
      'joins'=>'...'),
      array('limit'=>5','offset'=>5)
);