views:

277

answers:

1
table user:
|id|name|employee_priority_id|user_priority_id|
table priority:
|id|name|

As you can see, there are two foreign fields to the same table. But Kohana ORM default looks for a field called priority_id, which doesn't exist.

Is there a way to let Kohana ORM know that those two fields are an foreign key to that table.

+2  A: 

You can use 'aliasing' as documented @ http://docs.kohanaphp.com/libraries/orm/advanced#aliasingenhancing_the_meaning_of_your_relationships

So in your case, your User_Model would be:

class User_Model extends ORM {
    protected $belongs_to = array('employee_priority' => 'priority', 'user_priority' => 'priority');
}

BTW, according to Kohana's convention table names ought to be in plural form unless you override the $table_name, e.g:

class Priority_Model extends ORM {
    protected $table_name = 'priority';
}
Lukman