two relations "has one" referencing to the same table - Kohana 3.1 ORM

809 Views Asked by At

I have table messages with two foreign key: user_id_from and user_id_to. I need to retrieve both rows from table users with "has one" relation. How can I do that?

1

There are 1 best solutions below

0
On BEST ANSWER

I just noticed this is actually a belongs to relationship. So the code should be as follows...

protected $_belongs_to = array(
    'user_from' => array('model' => 'user', 'foreign_key' => 'user_id_from'),
    'user_to' => array('model' => 'user', 'foreign_key' => 'user_id_to')
);

The user_from and user_to can be changed to however you want to access them.

i.e.

$message->user_from

and

$message->user_to