I have three tables (Premises, Routes and Schedules):
Local Table:
id | nombreLocal
--------------------------
1 Local Uno
2 Local Dos
3 Local Tres
Routes Table:
id | id_local_origen | id_local_destino
--------------------------------------------------
1 1 2
2 2 3
Table Schedules:
id | id_rutas
---------------------
1 1
2 2
I have the following associations:
In the Locals table:
$this->hasMany('Rutas', [
'foreignKey' => 'id_local_origen'
]);
$this->hasMany('Rutas', [
'foreignKey' => 'id_local_destino'
]);
In the Routes table:
$this->belongsTo('Origen', [
'foreignKey' => 'id_local_origen',
'className' => 'Locales',
'joinType' => 'INNER'
]);
$this->belongsTo('Destino', [
'foreignKey' => 'id_local_destino',
'className' => 'Locales',
'joinType' => 'INNER'
]);
$this->hasMany('Programaciones', [
'foreignKey' => 'id_rutas'
]);
In the Schedules table:
$this->belongsTo('Rutas', [
'foreignKey' => 'id_rutas',
'joinType' => 'INNER'
]);
What I need for now friends please, is to solve using the CakePHP 3.6 ORM next thing in the view.ctp
In the index.ctp of Schedules, something like this must appear:
id | Origen | Destino
------------------------------------
1 Local Uno Local Dos
2 Local Dos Local Tres
============== In the Programming controller, I have this:
public function view($id = null)
{
$programacione = $this->Programaciones->get($id, [
'contain' => ['Rutas']
]);
$this->set('programacione', $programacione);
}
**
In other words, I have tables A, B, C A is already related to B and vice versa. B is already related to C and vice versa. What I would like to know please is how can I get fields from table A, being in table C?
**