Issue
Now I'm very tired so I can't think well. Sorry for anticipated if this a duplicate question and if my English is weird.
In CakePHP 3.0 I have the model "Asistencias". Is asosiated to "Ejecutivos". so, in asistencias table, I have de FK ejecutivo_id and works OK when i try to access data from the ejecutivos table because I made the correct declaration:
$this->paginate = [
//'contain' => ['Sucursales', 'Cedentes', 'Ejecutivos'],
'contain' => ['Ejecutivos'],
'limit'=>100,
'order'=>['Asistencias.entrada'=>'DESC', 'Ejecutivos.nombre'=>'DESC']
];
As you can see, I've commented the line 2. I take out the asosiation of Cedentes and Sucursales from Asistencias.
Now, the FKs sucursal_id and cedente_id belongs to ejecutivos table, instead asistencias table. It's help me to make others tasks in CakePHP that doesn't interest to you.
My question is how I can access to Sucursales and Cedentes in an efficient way? I guess I can't call them from the contain in the paginate properties.
I want use them in my view like this:
//index.ctp
foreach($asistencias as $asistencia){
echo $asistencia->ejecutivos->name;
echo $asistencia->ejecutivos->sucursal->name;
echo $asistencia->ingreso;
echo $asistencia->salida;
}
I just can't remember the correct way. Can you help me?
Solution
You can nest the contains to get your desired result.
$this->paginate = [
'contain' => [
'Ejecutivos' => [
'Sucursales', 'Cedentes',
],
],
'limit'=>100,
'order'=>['Asistencias.entrada'=>'DESC', 'Ejecutivos.nombre'=>'DESC']
];
Answered By - chrisShick
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.