Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ModelAdmin many_many relationship

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

Page: 1
Go to End
Author Topic: 982 Views
  • stew
    Community Member
    30 Posts

    ModelAdmin many_many relationship Link to this post

    Hey guys,

    I'm in the process of converting what had been a normal silverstripe project into one using the ModelAdmin simply because the client's requirements went through the roof and the ModelAdmin looks like the best way to achieve what I need to achieve. However I've hit a brick wall and need some help.

    Trying to explain what I want to achieve is a wee bit tricky but here goes,

    Organisations has many contacts (done), they have one category and one legal status (both done), they have many target groups - and this is where I'm stuck.

    I have created a TargetGroup bit in the ModelAdmin and populated with all the target groups that the client needs, however I can't get them into the Organisation bit, I've setup a many_many relationship in the Organisation.php file:

       static $many_many = array(
          'TargetGroups' => 'TargetGroup'

    However it's not pulling in the existing groups, it's only letting me create new ones the same way has_many does.

    I'm rather stumped as the tutorial (#5 Dataobject Relationship Management) doesn't help, I tried adding the getCMSFields(); code to Organisation.php and it didn't add in anything.

    I appreciate any help you can give me,


    Edit: I meant to add, there will be quite a few many_many relationships in the database for GeographicalArea, Venues etc. Don't know if this affects any of the code, wouldn't have thought so but just incase

  • stew
    Community Member
    30 Posts

    Re: ModelAdmin many_many relationship Link to this post

    Problem solved thanks to this thread: http://ssorg.bigbird.silverstripe.com/general-questions/show/279173

    Only found thanks to some magic Googling. lol.

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.