Kohana ORMを使用してデータベースから情報を取得しようとしています。ORM結合のKohana(KO3)列
枝
id smallint parent_id smallint name varchar active int
branches_options私はbranches_optionsテーブル
から情報を取得する次のコードでid mediumint branche_id smallint name varchar customer_id int
:2つの関連私のデータベース内のテーブルがあり
` $branchesOptions[] = ORM::factory('branches_option') ->where('branche_id', '=', $subBranche) ->join('branches', 'LEFT')->on('branches.id', '=', 'branches_options.branche_id') ->order_by('name') ->find_all() ->as_array();`
今、私は結果セット内のbranches.nameの値を見たいと思いますが、私はKohanaでこれを行う方法がわかりません。
モデルのコードは次のとおりです。
`class Model_Branche extends ORM { protected $_has_many = array( "options" => array('model' => 'branches_option'), "adwords_templates" => array ('model' => 'adwords_template') ); public $result = array();`
と
`class Model_Branches_option extends ORM { protected $_has_many = array ( "keywords" => array('model' => 'branches_options_keyword') ); protected $_has_and_belongs_to = array ( "adwords_templates" => array ( "model" => "adwords_template", "through" => "branches_options_templates" ) ); protected $_belongs_to = array ("branche" => array());`
この行うことができますし、そうであれば、どのように?
class Model_Branche extends ORM
{
protected $_has_many = array(
'options' => array(
'model' => 'branches_option',
'foreign_key' => 'branche_id'
)
);
}
そしてBranches_Optionモデルを(それがmodel/branche/
フォルダにする必要があります):これは正常に動作するために
モデルのコードを投稿できますか?あなたはそれらの間の関係を適切に定義しましたか? – Thorsten
モデルを追加するために私の質問を編集しました。 – Erik
これらの配列は何ですか? 'array( 'model' => 'branches_options_keyword') );'あなたのコードを適切に投稿してください。 '$ _has_and_belongs_to'とは何ですか? Kohanas ORMにはそのオプションはありません。 – Thorsten