【发布时间】:2016-08-29 20:44:21
【问题描述】:
我有下面的代码不能按预期工作。
模型中指定的关系:
public function getShift() {
return $this->hasOne(Shift::className(), ['id' => 'shift_id']);
}
public function getShiftName() {
return $this->shift->name;
}
查询:
$job_position = JobPositions::find()
->innerJoinWith(['shift'])
->where('month(date) = month(curdate())')
->one();
它给了我关于 job_position 表而不是 shift 表的数据。如何获取班次表的数据?
【问题讨论】:
标签: activerecord yii2 relationship