Complex Associations - CakePHP 3.x [ Nested belongsToMany]

I have a complex joining like

A belongs to Many B threw AB table
AB belongs to many C threw ABC table

Now my problem is how i can get data in controller A which contain result till table ABC.
Not finding direct relation in A and table ABC

My database structure is

Table A (id, name, code)
Table B (id, name, code)
Table C (id, name, code)
Table AB (id, a_id, b_id, fee)
Table ABC (ab_id, c_id, opt_date, tno)

I can connect with B using below query but not sure how to get data for ABC
contain => ['B']

contain => [
β€˜B’ => [β€˜C’]

A contain B, and B contain C.

you can access your data like this :

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


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

1 Like