I'm trying to retrieve information from a database using Kohana ORM.
There are two relevant tables in my database:
branches
id smallint
parent_id smallint
name varchar
active int
branches_options
id mediumint
branche_id smallint
name varchar
customer_id int
With the following code I want to retrieve the information from the branches_options table
` $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();`
Now I want to see the value of branches.name in the result set, but I'm not sure how to do this in Kohana.
The code of the models is:
`class Model_Branche extends ORM
{
protected $_has_many = array(
"options" => array('model' => 'branches_option'),
"adwords_templates" => array ('model' => 'adwords_template')
);
public $result = array();`
and
`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 () );`
Can this be done and if so, how?
array('model' => 'branches_options_keyword') );Please post your code properly. And what is$_has_and_belongs_to? Kohanas ORM does not have that option. - Thorsten$_has_and_belongs_topart. It looks a bit like KO2 code that should not be there. - Erik