I used this code, but only one table’s data selected.
I need to select all fields from two tables:
$options['joins'] = array(
array('table' => 'tbl_users',
'alias' => 'Users',
'type' => 'INNER',
'foreignKey' => 'assigned_by',
'fields' => 'Users.user',
'conditions' => array(
'TravancoAdmin.assigned_by = Users.id'
)
)
);
$options['conditions'] = array( 'TravancoAdmin.id' => $task_id);
$result = $this->find('all', $options);
return $result ? $result : 1;
How can i get all fields from two tables?
If there is any mistakes in my code?
You need to move the
'fields'option out of'joins'. Otherwise $this->find will only fetch the fields for the current model. Remember to add all fields you need when you specify'fields', both the ones for the current model and the ones you need from the table you’re joining.For example: