I have three tables Countries, Cities and Addresses. Their relationship is Countries hasMany Cities, Cities hasMany Addresses. So Its something like this Countries->Cities->Addresses.
If I want to get all addresses in a certain city I can do it like this
$this->paginate = [
'contain' => ['Cities']
];
$this->set('addresses', $this->paginate($this->Addresses));
If I want to get all Cities in a certain Country I can do like that as well.
What I want is I want to get all Addresses in a Certain Country.
Note: Addresses does not contain foreign key for Countries, instead its in the Cities.
Possible query would be: SELECT a.*, c.* FROM countries a LEFT JOIN cities b ON a.id=b.country_id LEFT JOIN addresses c ON b.id=c.city_id