我在cake php 1.3中编写了这个连接查询。
$supportbooks=$this->Supportbook->find('all',array('joins'=>array(
array(
'table'=>'supportbookstatuses',
'alias'=>'supportstatus',
'conditions' =>array('supportstatus.unique_id=Supportbook.`unique_key`')
)
)),array('conditions'=>array('Supportbook.user_id'=>$user_id)));
返回以下查询:
SELECT `Supportbook`.`id`, `Supportbook`.`category`, `Supportbook`.`user_id`, `Supportbook`.`email`, `Supportbook`.`subject`, `Supportbook`.`message`, `Supportbook`.`reply`, `Supportbook`.`unique_key`, `Supportbook`.`replied` FROM `fl_supportbooks` AS `Supportbook` JOIN `fl_supportbookstatuses` AS `supportstatus` ON (`supportstatus`.`unique_id`=`Supportbook`.`unique_key`) WHERE 1 = 1
where子句不起作用。应该有一个where子句:WHERE Supportbook.user_id = 21 我如何添加where子句?
答案 0 :(得分:1)
您出现了误诊。它应该是:
$supportbooks=$this->Supportbook->find('all',array('joins'=>array(
array(
'table'=>'supportbookstatuses',
'alias'=>'supportstatus',
'conditions' =>array('supportstatus.unique_id=Supportbook.`unique_key`')
)
),'conditions'=>array('Supportbook.user_id'=>$user_id)));