Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Trouble Unchecking MMDOM 'Show only related records'

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: 974 Views
  • dizzystuff
    Avatar
    Community Member
    93 Posts

    Trouble Unchecking MMDOM 'Show only related records' Link to this post

    Hey UC

    Just came across something a bit weird (to me at least). I have a MMDOM for which I had set set_only_related to true. I realised after testing that this was preventing the newly created item from appearing in the DOM because it had not been linked on creation so attempted to uncheck the Show Only Related Records checkbox - only to have it check itself and not reveal the missing item.

    Fair enough, I'm assuming then that that's the intended behaviour of the flag. (is there any way to set it to checked by default but allow it to be unchecked as required?)

    So I commented out the set_only_related(true) and tried again ... but the same thing happened, I unchecked the box, it thought for a moment, and then rechecked itself. I tried setting the flag to false, running /dev/build/, throwing a ?flush=1 on the admin url.... just shots in the dark really.

    Then I realised I have a second MMDOM for this particular Page type/subclass on a different tab in the admin also set with set_only_related to true. When I commented out this flag too, then the original began working correctly. So the second MMDOM set_only_related appears to have been affecting the first.

    Could this be a bug? The second MMDOM is attached to this Page class normally, the original one is implemented on the class via a decorator, if that makes a diff.

    Cheers
    dizzy

  • UncleCheese
    Avatar
    4085 Posts

    Re: Trouble Unchecking MMDOM 'Show only related records' Link to this post

    The "only related" functionality is commonly misunderstood and misused. Ideally, you should set the relation elsewhere (e.g. modeladmin) and use the MMDOM merely as a view of what is associated with that page. It's particularly useful if you want to sort the related objects uniquely on that page. There is a trick you can use if you want to force the relation on create. Use the onAfterWrite() method in your dataobject.

       public function onAfterWrite()
       {
          parent::onAfterWrite();
          if(isset($_POST['ctf'])) {
             // new record?
             if(!isset($_POST['ctf']['childID']))
                DB::query("INSERT INTO `Jon_Table` SET PageRelationID = ". $_POST['ctf']['sourceID'] . ", DataObjectID = $this->ID");
          }
       }

    974 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.