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, Ed, biapar, Willr, Ingo, swaiba

trigger creation of a record

Go to End

2 Posts   391 Views


Community Member, 52 Posts

19 January 2014 at 11:49pm

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?


Forum Moderator, 1362 Posts

20 January 2014 at 12:32am

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();