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
?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.