Search code examples
cakephpcontrollercontains

Cakephp contain inside another. It´s possible?


I am trying to make a cotain inside another. it's possible?

  $tareasp = $this->ProyectosCategoriasTareas
   ->find('all',
            ['contain' =>
                ['Tareas'=>
                    ['contain'=>
                         ['Photos']
                    ]
                ]
            ])
  ->where(['proyecto_id' => $proyecto['id']]);

I tried it but not work


Solution

  • You don't need to use the contain key multiple times, you can just nest the names:

    'contain' => [
        'Tareas' => [
            'Photos'
        ]
    ]
    

    or use dot notation:

    'contain' => [
        'Tareas.Photos'
    ]
    

    See also