我想将“部门”表加入我的分页结果。这是发生的事情:
我设置了分页变量,以便它加入扇区:
$this->paginate = array(
'joins' => array(
array(
'table' => 'sectors',
'alias' => 'Sector',
'type' => 'left',
'foreignKey' => false,
'conditions' => array('Company.sector_id = Sector.id'))),
'conditions' => $conditions);
然后走
$jobs = $this->paginate('Job');
分页器生成的查询已损坏,因为它在 Company 之前加入 Sector。这是sql输出的一部分:
SELECT COUNT(*) AS `count` FROM `jobs` AS `Job` left JOIN sectors AS `Sector` ON (`Company`.`sector_id` = 'Sector.id') LEFT JOIN `companies` AS `Company` ON (`Job`.`company_id` = `Company`.`id`)
它应该是:
SELECT COUNT(*) AS `count` FROM `jobs` AS `Job` LEFT JOIN `companies` AS `Company` ON (`Job`.`company_id` = `Company`.`id`) left JOIN sectors AS `Sector` ON (`Company`.`sector_id` = 'Sector.id')
我对 Job 模型进行了分页,它与 Company 模型相关,但与 Sector 模型无关。这就是为什么我需要通过分页加入该部门。
我怎样才能解决这个问题?