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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Trouble Unchecking MMDOM 'Show only related records'


Reply


2 Posts   1048 Views

Avatar
dizzystuff

Community Member, 93 Posts

11 July 2010 at 5:14pm

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

Avatar
UncleCheese

Forum Moderator, 4096 Posts

12 July 2010 at 5:47am

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");
      }
   }