1
我有表messages
有两个外键:user_id_from
和user_id_to
。 我需要从表users
中检索“有一个”关系的两行。 我该怎么做?两个关系“有一个”引用同一个表 - Kohana 3.1 ORM
我有表messages
有两个外键:user_id_from
和user_id_to
。 我需要从表users
中检索“有一个”关系的两行。 我该怎么做?两个关系“有一个”引用同一个表 - Kohana 3.1 ORM
我刚刚注意到这实际上是属于关系。所以代码应该如下...
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