Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Many-to-Many with Extra Field


Reply


2 Posts   2112 Views

Avatar
baontq

Community Member, 1 Post

11 December 2008 at 3:50am

Edited: 11/12/2008 3:50am

Hi all,

I am learning silverstripe by implement a simple school management system. I need help on this relationship issue:

A Class has many assigned Teachers, each teacher takes care a subject. So the relationship table should has a classID, teacherID and an extra field is subjectID. How can I implement the many-to-may relationship which has extra field like this one?

Thanks for help!

Avatar
Hamish

Community Member, 712 Posts

11 December 2008 at 7:59am

Really what you have is a three way many-many relationship (*snicker*) between Teachers, Classes and Subjects. The best way to bring them all together is to create a new class that has one of each. Eg:

<?php
class SchoolClassSubject {

static $has_one {
'MyClass' => 'SchoolClass',
'MyTeacher' => 'SchoolTeacher',
'MySubject' => 'SchoolSubject'
}
}
?>


And, of course, SchoolClass, SchoolTeacher and SchoolSubject all have a has_many relationship with SchoolClassSubject.