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?
我有两个外键的表消息:user_id_from和user_id_to。我需要从具有“has one”关系的表用户检索这两行。我怎样才能做到这一点?
1 个解决方案
#1
2
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.
user_from和user_to可以更改为您想要访问它们。
i.e.
即
$message->user_from
and
和
$message->user_to
#1
2
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.
user_from和user_to可以更改为您想要访问它们。
i.e.
即
$message->user_from
and
和
$message->user_to