1
votes
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 .

4

4 Answers

3
votes
$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

0
votes

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')
            )
)
)
0
votes

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')
                    )
                )
            )
      );
0
votes
$this->employee->bindModel(
    array('hasMany' => array(
        'Store' => array(
            'className' => 'Principle'
                )
            )
        )
    );