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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Managing many to many relationships

Go to End

2 Posts   2088 Views


Community Member, 288 Posts

9 July 2009 at 7:58pm

Edited: 09/07/2009 7:59pm


I am currently trying to manage many to many relationships in the CMS and I have run into some issues.
Everything works on the page that is on the many_many-side but I am getting strange behaviour from the page that is on the belongs_many_many-side. At first everything worked by using checkboxsetfield like this

$accessoryList = DataObject::get('AccessoryPage');
if ($accessoryList) {
	$fields->addFieldToTab('Root.Content.Accessories', new CheckboxSetField('Accessories', 'Related Accessories', $accessoryList));

But when I added a boolean field on the many-many page, suddenly the belongs_many_many-page checkboxsetfield is showing which pages have the boolean set to 1, not the relationship. Also trying to save the page now yields an error and it worked before I added the boolean field.

I have also tried using the ManyManyComplexTableField and the manymany version of dataobjectmanager for this but if it's used on the belongs_many_many-side I get an empty javascript alert-box and then simply "Error loading the page".

Neither of these feels like expected behaviour to me. I would really like to be able to manage the relationship from both ends and right now that seems to be impossible. Is this the way it's supposed to be?

Kindly, Marcus


Community Member, 288 Posts

9 July 2009 at 8:12pm


It seems like the CheckboxSetField solution works again on the belongs_many_many side.
Trying to use ManyManyComplexTableField still gives errors though.