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

Exception when using many_many and belongs_many_many

Go to End



Community Member, 26 Posts

6 February 2013 at 3:54am

Edited: 06/02/2013 3:55am

I have a DataObject called Staff which has a many_many relationship with a DataObject called Stage (which in turn has a belongs_many_many relationship with Staff). When editing the Staff items, Stages are connected using a CheckboxSetField.

Here's the problem. If I check any of the checkboxes before clicking on Create, I get an exception saying "ManyManyList::add() can't be called until a foreign ID is set". If I create the Staff item first, and then checks any of the checkboxes everything works fine. It's the same kind of problem you get if you try to upload an image into an Image field, before the parent DataObject has been created.

Is there any way to fix this? I think it's an incredibly stupid bug/feature, if it's supposed to be like this. My clients won't understand that they have to click on Create before clicking on the checkboxes. Extremely confusing.

In Staff.php:

static $many_many = array(
"Stages" => "Stage"

In Stage.php:

public static $belongs_many_many = array(
'Staff' => 'Staff'