Reputation: 15
SELECT e.employee_name, e.employee_store, e.employee_phone, s.store_address
FROM `employee` e
JOIN store s ON e.employee_store = s.store_name
How to write this query in cakephp controller and how to display result in view part .
Upvotes: 1
Views: 2935
Reputation: 43
$this->Model->find(
'all',
array(
'fields' => array('table.employee_name', 'table.employee_store', ....),
'joins' => array(
'table' => 'databasename.store',
'conditions' => array('employee_store' => 'store_name')
)
)
)
if you join multiple database connection database are on same server otherwise not working
Upvotes: 3
Reputation: 1
$this->employee->bindModel(
array('hasMany' => array(
'Store' => array(
'className' => 'Principle'
)
)
)
);
Upvotes: 0
Reputation: 2480
you should try this Employee is your Model name, stores is your table name and type is your joining left,right and inner
$details=$this->Employee->find('all',array('fields' => array('Employee.*','stores.*'),
'joins'=>array(
array(
'table'=>'store',
'type'=>'inner',
'conditions'=>array('Emmployee.employee_store=stores.store_name')
)
)
)
);
Upvotes: 0
Reputation: 31749
Try with -
$this->Model->find(
'all',
array(
'fields' => array('table.employee_name', 'table.employee_store', ....),
'joins' => array(
'table' => 'store',
'conditions' => array('employee_store' => 'store_name')
)
)
)
Upvotes: 0