I am trying to set up a product object in Kohana 3.3 using the built in ORM. I want it so that when I call:
$p1 = ORM::factory('product')
->where('product_type', '=', '1')
->find_all();
it will create an object of this structure:
Model_Product Object
(
[_long_list_of_kohana_properties] => Array ()
[_object:protected] => Array
(
[id] => 2
[product_type] => 1
...
[product_attributes] => Array (List of attributes)
)
)
Currently, it produces this:
Model_Product Object
(
[_long_list_of_kohana_properties] => Array ()
[_object:protected] => Array
(
[id] => 2
[product_type] => 1
...
)
)
This is the relevant code for the objects and the _has_many / _belongs_to :
class Model_Product extends ORM
{
protected $_db = 'default';
protected $_table_name = 'product';
protected $_primary_key = 'id';
protected $_table_columns = array(
'id',
'product_type',
...
);
protected $_has_many = array(
'product_attributes' => array(
'model' => 'productAttributes',
'foreign_key' => 'product_id',
'far_key' => 'id',
)
);
}
class Model_ProductAttribute extends ORM
{
protected $_db = 'default';
protected $_table_name = 'productAttributes';
protected $_primary_key = 'id';
protected $_table_columns = array(
'id',
'product_id',
'attribute_name',
'attribute_value',
);
protected $_belongs_to = array('product' => array(
'model' => 'product',
'foreign_key' => 'product_id',
'far_key' => 'product_id',
)
);
}
I can't seem to get the right combination of foreign_key and far_key values to make this work... Also, I can't find a good explanation of the purpose of "far_key". If someone can explain foreign vs far that might solve this problem, ha.
Any suggestions as to where I might be messing up?
Thank you in advance.