既然你聽不懂的語法,這是實際的查詢:
$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