Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » HasManyFileDOM & Setting Relations

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: 648 Views
  • Hamish
    Avatar
    Community Member
    712 Posts

    HasManyFileDOM & Setting Relations Link to this post

    Hi all, apologies if this has already been solved elsewhere, however UC's SVN repo seems to have disappeared behind authentication at this forum sucks for searching.

    I have an issue with HasManyFileDataObjectManager. If you use it to create a new related File object it will create it correctly however within the DOM the checkbox is not ticked. Consequently, if you then save the parent object without refreshing the page it will delete the relation.

    Anyone have any ideas how to get around that? It should populate the table ticked, but I can't for the life of me see where that is happening to fix it.

    Regards

    Hamish

  • UncleCheese
    Avatar
    4085 Posts

    Re: HasManyFileDOM & Setting Relations Link to this post

    The SVN is behind authentication? I can't imagine why. I haven't touched the settings in over a year. It says anonymous reads are still on, and in my testing, I'm not getting an authentication wall. That's bizarre.

    The problem you're describing could very well be a bug. HasManyDOM is so rarely used. I don't think I've tested it in a long time. I've never come across a situation where HasManyDOM was more practical than ManyManyDOM.

    So before I do any digging, you're sure that HasManyDOM is what you want? Usually $has_many relations are served better by a regular DOM.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: HasManyFileDOM & Setting Relations Link to this post

    Well I've always been prompted for a password when using the browser viewer, but that never stopped me looking at it or checking out until recently. Still a problem.

    Will try a ManyManyDOM - yes I'd prefer HasMany, but ManyMany will do.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: HasManyFileDOM & Setting Relations Link to this post

    FYI, it's probably why the module page downlink links are broken at the moment.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: HasManyFileDOM & Setting Relations Link to this post

    Hey UC, have access now (still asking for a login using Chrome - no idea why though). I've switched to latest trunk Uploadify + DOM and ManyManyFileDataObjectManager. Now uploading the file works, however the new DataObject created is not related to the parent object.

    That is:
    1. I select Add DataObject
    2. Upload file
    3. Fill in popup CMS forms for that DataObject
    4. Press Save
    5. Object appears in the database, but is not related to the parent object

    Any clues?

  • UncleCheese
    Avatar
    4085 Posts

    Re: HasManyFileDOM & Setting Relations Link to this post

    With MMDOM, you have to check the box after adding. There are some snippets out there that will force the check on add.

    Try this on your DataObject:

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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: HasManyFileDOM & Setting Relations Link to this post

    Thanks, I used a variation to get a partial solution - however I am now back to the original problem: The new record appears in the table un-ticked. Consequently, if I now save the record (without explicitly ticking the box) it is removed from the relationship again.

    EDIT: Ok, I think the problem is that the select values hidden field needs to be updated, eg it will look like this:

    <input id="Form_EditForm_ProjectFiles_CheckedList" name="ProjectFiles[selected]" type="hidden" value=",10678,10682,10977,10681,10680,10679,10710,10688,10697,10707,10687,10696,10706,10686,10695,10705,10685,10694,10704,10684,10693,10703,10692,10702,10691,10701,10690,10700,10709,10689,10698,10708,">

    So when the .refresh is called it doesn't check the box. Will post a solution when I find it

    EDIT2: Ok, for others who want this enabled, you need to modify FileDataObjectManager.php, the closePopup() method. Add the following line to the customScript:

    parent.jQuery(':input[name={$this->Name()}\[selected\]]').val('');

    This blanks the checked values list and it will default to all checked.

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