Let's say that I have a cities
table with a state_id
field, and a states
table with a country_id
field, as well as a countries
table that the country_id
field points to. So in CakePHP terms, Cities belongsTo States
, and States belongsTo Countries
.
Without altering the tables themselves, how do I make it so that for all intents and purposes, States belongsTo Countries
? In other words, what do I need to put in my table models to make it so that I can do:
$cityArray = $this->Cities->find('all', [ 'contain' => 'Countries' ])->toArray();
and have it return an array of Cities
, each of which contains a Country
, without having State
contained in the array?
Right now I'm editing the array post-query to remove State
and splice Country
back onto the City
, but I'm wondering if there's a more transparent way to do it.