既然你听不懂的语法,这是实际的查询:
$records = $this->Referee->find('all', array(
'fields' => array(
'Assumption.id', 'Referee.id', 'Referee.first_name', 'Referee.second_name'
),
'joins' => array(
array(
'table' => 'assumptions',
'alias' => 'Assumption',
'type' => 'INNER',
'foreignKey' => false,
'conditions' => array('Referee.id = Assumption.referee_id', 'Assumption.season_id = 7'),
),
),
)
);
将会产生这个查询:
SELECT
`Assumption`.`id`,
`Referee`.`id`,
`Referee`.`first_name`,
`Referee`.`second_name`
FROM `referees` AS `Referee`
INNER JOIN assumptions AS `Assumption`
ON (`Referee`.`id` = `Assumption`.`referee_id`
AND `Assumption`.`season_id` = 7)
其中提供您正在寻找的结果。
输出示例:
Array
(
[0] => Array
(
[Assumption] => Array
(
[id] => 1
[0] => Array
(
[id] => 1
[season_id] => 7
[referee_id] => 1
[name] => SomeAssumpton
)
)
[Referee] => Array
(
[id] => 1
[first_name] => Ref
[second_name] => one
)
)
)
这产生简单的查询,产生不必要的响应。我应该重现那个子查询。 – 2011-04-24 18:38:56
由于您无法理解语法,因此我为您编写了代码。它会产生你正在寻找的结果。 – 2011-04-24 22:34:07
如果你想要你的EXACT子查询,你唯一的其他选择就是使用:'$ this-> Referee-> query('{你的SUB-QUERY HERE}');'因为CakePHP没有子查询语法你想要写他们的方式。 – 2011-04-25 01:54:19