17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1869 Views |
-
Many-to-Many with Extra Field

11 December 2008 at 3:50am Last edited: 11 December 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!
-
Re: Many-to-Many with Extra Field

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.
| 1869 Views | ||
|
Page:
1
|
Go to Top |


