5

I'm having this problem with relationships with Codeigniter's DataMapper. I have an Interview model that has an author_id and an interviewee_id. They both relate to the user id in the user model.

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?

quantme
  • 3,609
  • 4
  • 34
  • 49
Nelo
  • 145
  • 10
  • 1
    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. So Changing `interviewee_id` to `user_id` seems to do the drill. Just in case someone has the same problem out there. – Nelo Mar 31 '12 at 01:16
  • 5
    Please feel free to post an answer to your own question to help others, if that that solved your issue: [answer] . You can [accept](http://meta.stackexchange.com/a/5235/159834) it after a day or two if no better answers come along. – Wesley Murch Mar 31 '12 at 03:46
  • Bumping this, hoping that @Nelo will create and accept an answer to remove this from the "Unanswered" queries. – swatkins Oct 11 '12 at 15:37
  • @Nelo I've added your comment as an answer. If you'd like to improve it, or provide your own answer as an actual answer please feel free. – Tim Post Feb 02 '13 at 00:20

1 Answers1

0

Quoting Nelo who answered his question in a comment:

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. So Changing interviewee_id to user_id seems to do the drill. Just in case someone has the same problem out there

Community
  • 1
  • 1
Tim Post
  • 33,371
  • 15
  • 110
  • 174