0

オブジェクトの子をロードする際に Kohana ORM に問題があります。
私のデータベーステーブルは次のようになります。

-objects (something like "houses", but objects sounds better in my opinion)
  -id
  -name
  -title
  -author
  -city (id link to cities.city_id)
  -description
  -access
-cities
  -city_id
  -country (id link to countries.country_name)
  -city_name
-countries
  -country_id
  -country_name

と私のモデル:

class Model_Object extends ORM
{
    protected $_table_name = 'objects';
    protected $_table_columns = array(
        'id' => NULL,'name' => NULL,
        'title' => NULL,
        'author' => NULL,
        'city' => NULL,
        'description' => NULL,
        'access' => NULL,
        'created' => NULL
    );
    protected $_primary_key = 'id';
    protected $_has_one = array(
        'city'=>array(),
        'author'=>array(
            'model'=>'User',
            'foreign_key'=>'user_id',
        )
    );
}

class Model_City extends ORM
{
    protected $_table_name = 'cities';
    protected $_table_columns = array('city_id'=>NULL,'city_name'=>NULL);
    protected $_primary_key = 'city_id';
    protected $_has_one = array('country'=>array(
        'model'=>'country',
        'foreign_key'=>'country',
    ));
    protected $_belongs_to = array(
        'objects'=>array(),
    );
}

class Model_Country extends ORM
{
    protected $_table_name = 'countries';
    protected $_table_columns = array(
        'country_id'=>NULL,
        'country_name'=>NULL,
    );
    protected $_primary_key = 'country_id';
    protected $_belongs_to = array(
        'cities'=>array(
            'model'       => 'city',
            'foreign_key' => 'country'
        ),
    );
}

国と都市の名前を含むオブジェクトのオブジェクトを取得する必要があります。私はこれを見つけました:

ORM::factory('Object')->with('City')->with('City:Country')->find_all();

ただし、都市オブジェクトではなく都市 ID を返します
私の質問は次のとおりです。提示されたテーブルで子オブジェクトを持つオブジェクトのオブジェクトを取得する方法は?

4

1 に答える 1