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

What's the right way to use DOM with DataObjectDecorator


Go to End


1250 Views

Avatar
opex

Community Member, 7 Posts

17 June 2012 at 11:35am

Edited: 17/06/2012 11:35am

I have this piece of code in my decorator, which is mostly copy-paste from FormScaffolder to add a field for the many_many attribute Contacts.

public function updateCMSFields(FieldSet &$fields) {
	$component = 'Contact';
	$relationship = 'Contacts';
	$relationshipFields = $this->getRelationshipFields();
	$filterWhere = $this->owner->getManyManyFilter($relationship, $component);
	$filterJoin = $this->owner->getManyManyJoin($relationship, $component);

	$dom =  new DataObjectManager($this->owner,
			$relationship,
			$component,
			$relationshipFields,
			"getCMSFields_forPopup",
			$filterWhere,
			'',
			$filterJoin
	);
	$tab = $fields->findOrMakeTab('Root.Main.Contacts',
			singleton($component)->i18n_plural_name());
	$tab->push($dom);
}

Existing contacts show up in the field as expected. But if I add a new contact, the contact it is saved in the Contact table, as expected, but the relation is not saved in the relationship table. If I replace DataObjectManager with ComplexTableField it works as it should.