我的表格结构如下:
恢复
-id
-...
的教育
-id
-resume_id
-degree_id
-...
度
-id
-name
我的简历模型是这样的:
class Resume extends Eloquent {
public function degree(){
return $this->hasManyThrough('Degree', 'Education', 'resume_id', 'degree_id');
}
}
形成的查询是:
select `education`.*, `degrees`.`resume_id` from `education` inner join `degrees` on`degrees`.`id` = `education`.`degree_id` where `degrees`.`resume_id` = 36035
但我想要的是:where education.resume_id = 36035
或者还有其他更好的方法来链接查询,以便我可以直接从简历中访问学位表,如$ resume-> degree 我甚至尝试过急切的加载方式,但无法通过链接检索数据
答案 0 :(得分:1)
我认为最好使用belongsToMany
。
可能是这样的:
public function degree()
{
return $this->belongsToMany('Degree')->withPivot('resume_id');
}