Я пытаюсь настроить объект продукта в Kohana 3.3, используя встроенный ORM. Я хочу, чтобы это так, что, когда я называю:Kohana 3.3 ORM _has_many _belongs_to
$p1 = ORM::factory('product')
->where('product_type', '=', '1')
->find_all();
создаст объект этой структуры:
Model_Product Object
(
[_long_list_of_kohana_properties] => Array()
[_object:protected] => Array
(
[id] => 2
[product_type] => 1
...
[product_attributes] => Array (List of attributes)
)
)
В настоящее время он производит это:
Model_Product Object
(
[_long_list_of_kohana_properties] => Array()
[_object:protected] => Array
(
[id] => 2
[product_type] => 1
...
)
)
Это соответствующий код для объектов и _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',
)
);
}
Я не могу найти правильную комбинацию значений foreign_key и far_key, чтобы сделать эту работу ... Кроме того, я не могу найти хорошее объяснение цели «far_key». Если кто-то может объяснить иностранные или далеко, что может решить эту проблему, ха.
Любые предложения относительно того, где я могу испортиться?
Заранее спасибо.