1
table user:
|id|name|employee_priority_id|user_priority_id|
table priority:
|id|name|
引用带有两个不同外键的表正如您所看到的,同一个表中有两个外部字段。但Kohana ORM默认查找名为priority_id的字段,该字段不存在。Kohana ORM
有没有办法让Kohana ORM知道这两个字段是该表的外键。
table user:
|id|name|employee_priority_id|user_priority_id|
table priority:
|id|name|
引用带有两个不同外键的表正如您所看到的,同一个表中有两个外部字段。但Kohana ORM默认查找名为priority_id的字段,该字段不存在。Kohana ORM
有没有办法让Kohana ORM知道这两个字段是该表的外键。
你可以用“走样”的记载@http://docs.kohanaphp.com/libraries/orm/advanced#aliasingenhancing_the_meaning_of_your_relationships
所以你的情况,你的User_Model是:
class User_Model extends ORM {
protected $belongs_to = array('employee_priority' => 'priority', 'user_priority' => 'priority');
}
BTW,根据Kohana中的惯例表名应该是复数形式,除非您覆盖$ table_name,例如:
class Priority_Model extends ORM {
protected $table_name = 'priority';
}