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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

onBeforeWrite calls


Go to End


1258 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?