我在名为inner
的分页模型中有join
Application
个查询
Application
有很多AssignedExploration
AssignedExploration
属于Exploration
Exploration
属于ExplorationCategory
ExplorationCategory
属于Season
到目前为止,我的查询是:
$session_condition = array(
'table' => 'assigned_explorations',
'alias' => 'AssignedExploration',
'type' => 'INNER',
'conditions' => array(
'AssignedExploration.application_id = Application.id',
'OR' => array(
array('AssignedExploration.label' => $this->request->named['filter_session'])
)
)
);
我想在OR
内添加另一个查询,applications
Season.name = fall
我尝试添加array('Season.name' => 'fall')
:
$session_condition = array(
'table' => 'assigned_explorations',
'alias' => 'AssignedExploration',
'type' => 'INNER',
'conditions' => array(
'AssignedExploration.application_id = Application.id',
'OR' => array(
array('AssignedExploration.label' => $this->request->named['filter_session']),
array('Season.name' => 'fall')
)
)
);
但没有运气。似乎季节未被AssignedExploration
识别。
我想从AssignedExploration
嵌套到Exploration
到ExplorationCategory
和Season
我不知道如何通过cakephp通过inner
join
查询。
先谢谢。
编辑:截至目前的查询:
INNER JOIN
`ntc_development`.`assigned_explorations` AS `AssignedExploration` ON (
`AssignedExploration`.`application_id` = `Application`.`id`
AND
`AssignedExploration`.`label` = 'fall'
)
答案 0 :(得分:0)
$this->paginate['Application'] = array(
'recursive' => -1,
'joins' => array(
array(
'table' => 'assigned_explorations',
'alias' => 'AssignedExploration',
'type' => 'inner',
'foreignKey' => true,
'conditions' => array('AssignedExploration.application_id = Application.id')
),
array(
'table' => 'seasons',
'alias' => 'Season',
'type' => 'inner',
'foreignKey' => true,
'conditions' => array('Season.id = Application.season_id') # whats your foregin key
),
),
'fields' => array(),
'conditions' => array('Season.name' => 'fail'),
);