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


Reply


2 Posts   201 Views

Avatar
voodoochile

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?

Avatar
martimiz

Forum Moderator, 1132 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();
}