Complex Associations - CakePHP 3.x [ Nested belongsToMany]

$this->A->find(‘list’,[
contain => [
‘B’ => [‘C’]
]
]);

A contain B, and B contain C.

you can access your data like this :

$data = $this->A->find()->contain([‘B’ => [‘C’]])

$data->data_of_a
$data->b->data_of_b
$data->b->c->data_of_c

or use debug() on your output to see how to your data is.

1 Like