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.

We've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Complicated many many relationship

Go to End

2 Posts   1244 Views


Community Member, 105 Posts

29 March 2017 at 3:52pm

I would like to create a many many relationship, as per the tutorials. So far so good.
I'll use class Mentor from to illustrate my idea.

What if there are different types of Mentors? Each mentor has a set skill. Some mentors have business skills, some have communication skills, etc. How would those different types be represented in such a way that when a mentor is added, their specific skill can be nominated?

The reason I ask this, is because I wish to be able to create various types that have secret information that should be used in a template, but someone using the many to many relationship doesn't need to worry about.

So for example: Mentor has a property called code.
In BusinessMentor it is set to 12A, and in CommunicationMentor it is set to 45C. Every Mentor who is a BusinessMentor has this code 12A. Every Mentor who is a CommunicationMentor has the code 45C.

When people are selecting Mentor's for the project in the CMS user interface, they don't need to worry about the underlying code, they just find the Mentor name and use that.

But that code is accessible in a template. Should the code be a DataObject itself?

Any ideas?


Community Member, 60 Posts

31 March 2017 at 8:43pm

You could add in the code in an onBeforeWrite() function based on selecting a 'type' for the mentor. For example:

class Mentor extends DataObject {
    private static $db = array(
        'Name' => 'Varchar',
        'Type' => 'Enum("BusinessMentor, CommunicationsMentor")',
        'Code' => 'Text'
   function onBeforeWrite(){
      if($this->Type && $this->Type == 'BusinessMentor'){
          $this->Code = '12A';