Tables:
Province hasMany County
, County belongsTo Province
, County hasMany City
, City belongsTo County
So basically something like: City belongsThroughCountyTo Province
Situation:
In a search form I have a select drop down menu with provinces.
The "code":
When I list the results, I first get ids of counties that belong to the specified province, and then do a City.county_id IN (array_of_counties_ids_here)
.
Question:
My question is, could I be doing it in a better way? Without first accessing the counties table. A simple three way join should do the trick, but I don't have an idea on how to implement it in Cake.
Adding a province_id
field to the cities table isn't a solution in my case (can't alter tables).