Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

php - Laravel 5:以一对多关系链接多对多关系(Laravel 5 : Chain many to many relation with one to many relation)

I have three tables in my database : 1) Teacher 2) Course 3) Timetable

(我的数据库中有三个表格:1)老师2)课程3)时间表)

Teacher and Course tables are connected through many to many relationship as each teacher can teach many courses and each course can have many teachers:

(教师和课程表之间通过多对多的关系联系在一起,因为每个老师可以教很多课程,并且每个课程可以有很多老师:)

-----------------          ------------------------         ----------------      
     Teacher                   CourseTeacher                    Course
-----------------          -------------------------        ----------------
id         name            id  course_id   teacher_id        id       name
1          John             1    1            1              1       English

Teacher -> ManyToMany -> Course

(老师 -> ManyToMany-> 课程)

Now foreach course , a teacher can have a many days with time on which he teaches that specific course,so there would be another table named timetable which has the following structure:

(现在,对于每门课程,一位老师可以花很多时间来教授该特定课程,因此将有另一个名为时间表的表格,其结构如下:)

---------------------------------------------------
                     TimeTable
----------------------------------------------------
id    day         time       teacher_id    course_id
1     monday      10:00 pm     1              1
2     tuesday     10:00 pm     1              1

Now the question is how can i connect the timetable table with CourseStudent relation through one to many relationship .

(现在的问题是,如何通过一对多关系将时间表与CourseStudent关系连接起来。)

For each teacher teaching the course i need to save the timetable of teacher for that specific course .

(对于每位教这门课程的老师,我需要保存该课程的时间表。)

Teacher -> ManyToMany -> Course
          |
          |
     One to Many
          |
      TimeTable
  ask by MSD translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...