Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Exception when using many_many and belongs_many_many

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

Page: 1
Go to End
Author Topic: 381 Views
  • Rodskagg
    Community Member
    8 Posts

    Exception when using many_many and belongs_many_many Link to this post

    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'

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.