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.

Data Model Questions /

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

onBeforeWrite calls


Go to End


1654 Views

Avatar
ismooth

Community Member, 25 Posts

8 March 2013 at 10:42pm

Hi,

I've extended Member object with onAfterWrite function that adds users to contacts group. Here is the code:

class MemberContact extends DataExtension {	

	static $belongs_many_many = array(
				'Companies' => 'Company'
			);

	function onAfterWrite() {
		$group = Group::get()
						->filter('Code', 'contacts')
						->first();
		$this->owner->Groups()->add($group);
		parent::onAfterWrite();
	}	
}

As you can notice there is many_many relation of Member with Company dataObject. My question is that it seems that onAfterWrite (or onBeforeWrite for that matter) doesn't get called when I add a member as many_many relation to Company object (through admin interface (modeladmin)). It gets called when I create new member, though. How can I achieve this? Is this feature or a bug?