Jump to:

7938 Posts in 1542 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Many to many relationship

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 666 Views
  • Stef87
    Avatar
    Community Member
    66 Posts

    Many to many relationship Link to this post

    Question changed to be more specific
    Firstly I'm using SilverStripe 2.4.7. I am tearing my hair out trying to figure out how to do this and I need to help.

    Ok so I have a dataobject and I use a dataobjectmanager on the admin's page to look after all of the dataobjects. I also use dataobjectmanager on other user's pages to look after the dataobjects that only relate to them. So the fields in the dataobject are used in the popups on both types of pages (the admin and the user pages).

    I need to add a checkbox to the admin page popup only so that when they create one of these dataobjects they can select multiple users and then the ids are saved in a linked table. I hope I'm being clear.

    I have my getCMSFields function in my dataobject (Offer) and getCMSFields in AllOffers with a dataobjectmanager. how to I add the checkbox without adding it to every other page too?

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Many to many relationship Link to this post

    I'm not sure I entirely follow your question, but if I understand correctly, it is about permissions rather than working with the dataobject-manager or relationships ?

    You can check whether the user has Admin-rights , and then based on that add the field to the user-interface.

    if(Permission::check('ADMIN')) return true;

    Make sure to also secure your dataobject-class (you can override the canCreate() / canDelete() methods). E.g. :

    function canCreate($member){
    if (Permission::check('ADMIN')) return true;
    }

  • Stef87
    Avatar
    Community Member
    66 Posts

    Re: Many to many relationship Link to this post

    Hi Fuzz10, thanks for your quick response.

    I apologise for being unclear. I'll try to simplify. Basic users have there own page (which only they have access to) and can create movies (dataobject). The movies they create are only linked to them. The admin can edit all movies or create global ones, through their page, that apply to everyone (hence the linked table). Yes I had tried something like that.

    if(Permission::check('ADMIN'){
    if (! empty($stores))
        {
             
          $checkBox = new CheckboxSetField(
             $name = "Stores",
             $title = "Select Stores",
             $source = $stores
          );

          $fields->push($checkBox);
       }
    }

    But while this displayed the checkboxes perfectly, it caused a problem with saving in the database. Basically it just didn't save. I was thinking I need a function to populate the linked list but this seems like a bit of a hacky workaround.

    I was also old that I should move that to the page rather than the dataobject but I'm not sure how.

    666 Views
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.