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?

Was it helpful?

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
scroll top