In a model, is it possible to do multiple iterations of belongsTo?
Assuming 3 tables, alerts, schedules, tasks and the model is for alerts. I want to get at a field from tasks but I have to join through schedules.
alerts.schedule_id -> schedules.tasks_id -> tasks.name
I tried this syntax:
var $belongsTo = array(
'Schedule' => array(
'className' => 'Schedule',
'foreignKey' => 'schedule_id'
),
'Task' => array(
'className' => 'Task',
'foreignKey' => 'task_id'
));
But that just joins both Schedules and Tasks directly to Alerts (here's the sql that was generated:
LEFT JOIN `schedules` AS `Schedule` ON (`Alert`.`schedule_id` = `Schedule`.`id`) LEFT JOIN `tasks` AS `Task` ON (`Alert`.`task_id` = `Task`.`id`)
)