Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » onBeforeWrite calls

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

Page: 1
Go to End
Author Topic: 532 Views
  • ismooth
    Avatar
    Community Member
    22 Posts

    onBeforeWrite calls Link to this post

    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?

    532 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.