two relations “has one” referencing to the same table - Kohana 3.1 ORM
-
14-11-2019 - |
Question
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?
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow