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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

HasManyFileDOM & Setting Relations


Go to End


7 Posts   963 Views

Avatar
Hamish

Community Member, 712 Posts

3 December 2010 at 4:50pm

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 December 2010 at 5:37pm

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.

Avatar
Hamish

Community Member, 712 Posts

6 December 2010 at 7:19pm

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.

Avatar
Hamish

Community Member, 712 Posts

6 December 2010 at 7:31pm

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

Avatar
Hamish

Community Member, 712 Posts

14 December 2010 at 4:31pm

Edited: 14/12/2010 4:33pm

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

15 December 2010 at 4:03am

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

Avatar
Hamish

Community Member, 712 Posts

16 December 2010 at 12:07pm

Edited: 16/12/2010 1:18pm

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.