Let's say I have 3 models.
- User (users of the system)
- Applicant (More details on each user such as address, phone, interested_position, etc)
- Position (In table applicants I only store interested position as position_id, this is where the position's description)
This is my model php files.
class User extends AppModel {
public $hasOne = 'Applicant';
}
class Applicant extends AppModel {
public $belongsTo = array('User', 'Position');
}
class Position extends AppModel {
public $hasMany = 'Applicant';
}
This is my UsersController.php
class UsersController extedns AppController {
public function index() {
$this->User->find('all');
{
}
When execute /users/index I got SQL statement on SQL dump as follow.
select *
from users
left outer join applicants
on users.id = applicants.user_id
But this is what I need.
select *
from users
left outer join applicants
on users.id = applicants.user_id
left outer join positions
on positions.id = applicants.position_id
So what to do in CakePHP to get this kind of result.
Thanks all.