我有以下三个表
课程表
blogdown:::serve_site()
章节部分表
output:
html_document:
pandoc_args: --lua-filter=color-text.lua
章节表
ID | title |
---|-----------|
1 | course 1 |
我对关系的定义如下。
课程模式
ID | course_id | title |
---|-----------|-------------------|
1 | 1 | Chapter Section 1 |
2 | 1 | Chapter Section 2 |
CHAPTER_SECTION模型
ID | chapter_section_id | title |
---|--------------------|-----------|
1 | 1 | Chapter 1 |
2 | 2 | Chapter 2 |
现在,我只想从“章节”表中获取标题列。提到see live,这是我的尝试。
public function chapterSections() {
return $this->hasMany('App\CHAPTER_SECTION', 'course_id');
}
我从课程表和Chapter_sections表中获取列,但是我没有从章节表中获取列,而是得到了空数组。
我的邮递员输出
public function chapterSections() {
return $this->hasMany('App\CHAPTER_SECTION', 'course_id');
}
我要获取的只是ID和标题列的章节表。这是我想要的输出。
COURSE::with('chapterSections.chapters:id,title')->get();
有没有做任何关系的方式,或者我必须使用联接来获得以上输出
答案 0 :(得分:0)
您也可以通过在章节章节中使用with,将章节包含在章节章节中。
如果要让它们包含所有响应,则可以在本节中声明$ with。
如果只希望对此响应使用它们,则可以像在课程中那样完全使用静态方法。
祝你好运