I have a question which seems is repeated but it's not:
I explain with a small example.
I have two table: Students & courses.
Each Student can take N courses and each course can be taken by N students.
I want to have access the courses by Students and also have access to Students by courses.
EX:
1- Give me the list of courses that Student with id=1 took.
2- Give me the list of Students who took the Course with id=2000.
If I use belongsToMany in StudentsTable Class is enough or I should Also define hasMany or belongsToMany in CoursesTable class.
Tell me what should I do.
Thank in advance.
PS: I use CakePHP 3.x
hasMany Through
.I recommend to visit the official site of Cakephp. They have provided a great example in book.cakephp.org/2.0/en/models/… – Agam Bangastudents
table,courses
table and the connecting table labelledstudents_courses
, but really you can name it whatever you want. I usually go with something easy to understand likestudent_course_links
.students_courses
should contain its own primary key and the foreign keys for both students and courses. I feel like the documentation is good enough, but if you need me to explain more i will try – Jason Joslin