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, Ed, biapar, Willr, Ingo

Many-to-Many with Extra Field

Go to End

2 Posts   2629 Views


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!


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:

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.