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 forum.silverstripe.org 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.

Data Model Questions /

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

Managing many to many relationships


Go to End


2 Posts   2446 Views

Avatar
MarcusDalgren

Community Member, 288 Posts

9 July 2009 at 7:58pm

Edited: 09/07/2009 7:59pm

Hello.

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

Avatar
MarcusDalgren

Community Member, 288 Posts

9 July 2009 at 8:12pm

UPDATE

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