Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Managing many to many relationships

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

Page: 1
Go to End
Author Topic: 1645 Views
  • MarcusDalgren
    Community Member
    288 Posts

    Managing many to many relationships Link to this post


    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

  • MarcusDalgren
    Community Member
    288 Posts

    Re: Managing many to many relationships Link to this post


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

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.