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.

Data Model Questions /

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

ModelAdmin many_many relationship

Go to End

2 Posts   1436 Views


Community Member, 30 Posts

22 July 2010 at 9:55pm

Edited: 22/07/2010 9:57pm

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 :)


Community Member, 30 Posts

22 July 2010 at 10:11pm

Edited: 22/07/2010 10:11pm

Problem solved thanks to this thread:

Only found thanks to some magic Googling. lol.