简体   繁体   English

CodeIgniter / Datamapper:同一个表的两个一对多关系不起作用

[英]CodeIgniter/Datamapper: Two one-to-many relationships to the same table not working

I'm having this problem with relationships with Codeigniter's DataMapper . 我在与CodeigniterDataMapper的关系中遇到了这个问题。 I have an Interview model that has an author_id and an interviewee_id . 我有一个具有author_idinterviewee_idInterview模型。 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 seemsuser_id seems练习。 Just in case someone has the same problem out there 以防有人在那里遇到同样的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM