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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   773 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, 1391 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();
}