Moumita Paul
Moumita Paul

Reputation: 21

Cake php join query

I have write this join query in 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)));

This return the following query:

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

The where clause is not working. There should be a where clause : WHERE Supportbook.user_id=21 How will I add the where clause?

Upvotes: 0

Views: 367

Answers (1)

Serpes
Serpes

Reputation: 672

You have a parentesis error. It should be:

$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)));

Upvotes: 1

Related Questions