[英]CodeIgniter/Datamapper: Two one-to-many relationships to the same table not working
I'm having this problem with relationships with Codeigniter's DataMapper . 我在与Codeigniter的DataMapper的关系中遇到了这个问题。 I have an
Interview
model that has an author_id
and an interviewee_id
. 我有一个具有
author_id
和interviewee_id
的Interview
模型。 They both relate to the user id in the user model. 它们都与用户模型中的用户ID相关。
I've been trying several approaches and none work; 我一直在尝试几种方法而没有工作; this is what I have right now:
这就是我现在所拥有的:
class Interview extends DataMapper
{
var $has_one = array(
'interviewee' => array(
'class' => 'user',
'other_field' => 'done_interview'),
'author' => array(
'class' => 'user',
'other_field' => 'written_interview')
);
}
class User extends DataMapper
{
var $has_many = array(
'done_interview' => array(
'class' => 'interview',
'other_field' => 'interviewee'),
'written_interview' => array(
'class' => 'interview',
'other_field' => 'author')
);
}
How do I let DataMapper know that one relationship will go through author_id
, and the other through interviewee_id
? 我如何让DataMapper知道一个关系将通过
author_id
,另一个通过interviewee_id
?
Quoting Nelo who answered his question in a comment: 引用在评论中回答他的问题的Nelo :
It seems there needs to be a user_id field
necessarily and then for the other relationships I can name the fields however I want. 似乎必须有一个
user_id field
,然后对于其他关系我可以命名我想要的字段。 So Changing interviewee_id
to user_id seems
to do the drill. 所以将
interviewee_id
更改为user_id seems
是user_id seems
练习。 Just in case someone has the same problem out there 以防有人在那里遇到同样的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.