次のようなMySQLテーブル構造があります。
国->Countries_Regions(FK:country_id)-> Countries_Regions_Cities(FK:region_id)
つまり、国と地域の間には1対多の関係があり、地域と都市の間には1対多の関係があります。
私はそれらを次のクラスとリンクさせようとしました:
class Model_Country extends ORM {
protected $_has_many = array('regions' => array("model" => "Countries_Region"));
}
class Model_Countries_Region extends ORM {
protected $_has_many = array('cities' => array("model" => "Countries_Regions_City"));
protected $_belongs_to = array('country' => array("model" => "Country"));
}
class Model_Countries_Regions_City extends ORM {
protected $_belongs_to = array('region' => array("model" => "Countries_Region"));
}
すべての地域を検索しようとすると、すべてうまくいきます
$country = ORM::factory("country", 1);
$region = $country->regions->find_all();
しかし、私がすべての都市をボトムアップで見つけようとすると、
$country = ORM::factory("country", 1);
$city = $country->regions->cities->find_all();
リージョン内のcityプロパティを認識しますが、すべてのcity値がNULLに設定された空の行を返します。
当たり前のことを見逃しているような気がしますが、それが何なのかわかりません。私を助けてください。