我的表messages
有两个外键:user_id_from
和user_id_to
。
我需要从表users
检索两行,并且“有一个”关系。
我怎么能这样做?
答案 0 :(得分:2)
我只是注意到这实际上属于一种关系。所以代码应该如下......
protected $_belongs_to = array(
'user_from' => array('model' => 'user', 'foreign_key' => 'user_id_from'),
'user_to' => array('model' => 'user', 'foreign_key' => 'user_id_to')
);
user_from和user_to可以更改为您想要访问它们。
即
$message->user_from
和
$message->user_to