Kohana ORM关系和显示信息

Kohana ORM关系和显示信息,orm,kohana,Orm,Kohana,我不知道该怎么做 假设我有3个模型,A、B和C 模型A有许多C,模型B有许多C,C属于A和B 我得到了所有的B $getBs=ORM::factory('B')->find_all(); 我显示A、B、C foreach($getBs as $getB) { echo $getB->b_category_title; foreach($getB->C->find_all() as $getC) { echo $getC->

我不知道该怎么做

假设我有3个模型,A、B和C

模型A有许多C,模型B有许多C,C属于A和B

我得到了所有的B

$getBs=ORM::factory('B')->find_all(); 
我显示A、B、C

foreach($getBs as $getB)
{
    echo $getB->b_category_title;
    foreach($getB->C->find_all() as $getC)
    {
        echo $getC->c_title;
        echo $getA->a_author; //Problem part
    }
}
在显示模型C的信息时,我不知道如何访问模型A并将其连接到模型C

编辑 为了获得工作代码,我将模型A-C更改为模型1-3

使用biakaveron的_load_with示例,我得到以下错误:

Database_Exception [ 1054 ]: Unknown column 'three.id_c' in 'on clause' [ SELECT `ones`.`a_id` AS `ones:a_id`, `ones`.`a_author` AS `ones:a_author`, `three`.* FROM `threes` AS `three` JOIN `twos_threes` ON (`twos_threes`.`id_c` = `three`.`c_id`) LEFT JOIN `ones` AS `ones` ON (`ones`.`a_id` = `three`.`id_c`) WHERE `twos_threes`.`id_b` = '1' ]
型号:

class Model_One extends ORM {

protected $_primary_key = 'a_id';

protected $_has_many = array(
    'threes'=> array(
        'model' => 'three',                
        'through' => 'ones_threes',   
        'far_key' => 'id_c',       
        'foreign_key' => 'id_a'   
        ),
    );
}

class Model_Two extends ORM {

protected $_primary_key = 'b_id';

protected $_has_many = array(
    'threes'=> array(
        'model' => 'three',                
        'through' => 'twos_threes',   
        'far_key' => 'id_c',       
        'foreign_key' => 'id_b'   
        ),
    );
}

class Model_Three extends ORM {

protected $_primary_key = 'c_id';

protected $_belongs_to = array(
    'ones'=> array(
        'model' => 'one',                
        'through' => 'ones_threes',    
        'far_key' => 'id_a',       
        'foreign_key' => 'id_c'   
        ),

'twos'=> array(
        'model' => 'two',                
        'through' => 'twos_threes',    
        'far_key' => 'id_b',       
        'foreign_key' => 'id_c'   
        ),
);

protected $_load_with = array('ones');
}
为什么要找三个身份证

C属于A和B

附言,只是一张纸条。您可以使用
$\u load\u和
属性加载C和A对象:

class Model_C extends ORM {
    // ...
    protected $_load_with = array('A');
    // ...
}

只是好奇
\u load\u with
属性是如何工作的?假设表C通过列“a_id”与表a有关系。科哈纳如何与这一切相匹配?表名和列名是否需要特殊格式?
$\u load\u with
只包含一个关系别名,在
$\u-beliens\u-to
属性中有详细说明。这与加载模型之前使用('A')
调用
->相同。当我使用_load_with属性时,我遇到了一个错误。我在帖子中添加了错误。为什么
'foreign\u key'=>'id\u c'
?我想应该是
'foreign\u key'=>'c\u id'
。检查您的外键名称。
class Model_C extends ORM {
    // ...
    protected $_load_with = array('A');
    // ...
}