I have two tables in a database, one as user(id,first_name,last_name)
, and the other one as location(id,country)
.
I need to perform an inner join with these two tables based on the condition user.id = location.id
, and the query result should contain the columns first_name
, last_name
and country
.
I have tried the following query in CakePHP:
$this->set('users', $this->User->find('list', array(
'fields' => array(
'User.id',
'User.first_name',
'location.country'
),
array(
'joins' => array(
array(
'table' => 'location',
'alias' => 'location',
'type' => 'INNER',
'conditions' => array('User.id = location.id')
)
)
)
)));
which however produces this error:
Unknown column 'location.country' in 'field list'
What could be the problem?