Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Many-to-Many with Extra Field

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

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

Page: 1
Go to End
Author Topic: 2048 Views
  • baontq
    Avatar
    Community Member
    1 Post

    Many-to-Many with Extra Field Link to this post

    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!

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Many-to-Many with Extra Field Link to this post

    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.

    2048 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.