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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

trigger creation of a record


2 Posts   150 Views


19 January 2014 at 11:49pm Community Member, 52 Posts

Hi all

I have a dataobject called nuts and another called bolts, I am trying to figure out how when a new entry for nuts is created to also create a new entry for bolts.

I am thinking to use onafterwrite but not sure of what to use to request the record creation.

Can anyone please point me in the right direction?


20 January 2014 at 12:32am Forum Moderator, 1091 Posts

Something simple, to get you going, in this case assuming Bolt has a NutID :)

$bolt = Bolt::get()->filter(array('NutID' => $this->ID));
if (!$bolt) {
$bolt = new Bolt():
$bolt->NutID = $this->ID;
$boltID = $bolt->write();