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?