【问题标题】:left join in yiileft join yii
【发布时间】:2012-04-19 10:03:13
【问题描述】:

我有 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')),


        );
    }

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

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

【问题讨论】:

  • 你好@jon 请给我查询(关系)...我想要来自 student_info 表的 first_name 和 last_name 以及来自 student_job_log 的 created_dt
  • 我做不到。如果您有一个有充分记录的具体问题,我可以提供帮助。
  • 在我这样写的视图文件中 echo $data->student_info;exit;nothing iscoming output
  • 抱歉,这还远远不够。
  • 你提到你收到了一个错误,但你没有说它是什么错误。此外,如果您有echo $data->student_info;exit;,则student_info 中可能没有内容,因此什么也不显示。您向我们展示了部分代码,而不是告诉我们问题所在。如果没有更多信息,没有人可以帮助您。

标签: yii criteria


【解决方案1】:

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

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

现在像使用它

echo $job->student_info->first_name . ', ' . $job->student_info->last_name;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-14
    • 2010-09-29
    • 2011-10-13
    • 2014-08-10
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    相关资源
    最近更新 更多