-1

我有 2 个表
student_job_log ->id,job_id,student_id,created_dt
student_info ->id,user_id,first_name,last_name

我已经在模型中建立了关系(studentJobLog)

public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        'student_info'=>array(self::BELONGS_TO,'StudentInfo','id','joinType'=>'LEFT JOIN',
                                    'select'=>'first_name, last_name')),


        );
    }

我得到了这个错误是什么问题。我的关系出了点问题,我不知道 :(

我想要学生信息中的名字和姓氏,请帮助我...... :(

4

1 回答 1

0

外键必须是您当前模型中映射到 StudentInfo 的那个

    return array(
    'student_info'=>array(self::BELONGS_TO,'StudentInfo','student_id',),
    );

现在像这样使用它

echo $job->student_info->first_name . ', ' . $job->student_info->last_name;
于 2012-04-19T16:13:50.760 回答