In SilverStripe 2.4, I was able to get ID of parent DataObject “A” in onAfterWrite() method of child dataobject “B” by
$this->AClassID
How to get “A”‘s ID in “B”‘s onAfterWrite() method ?
Note:”A” has many “B”s and “B” has one “A” (one-to-many relationship).
Sample code here for kind consideration:
Use if statement to make sure it is not 0 before continuing. like
Or
The reason is that it is called multiple times and you just need to execute when it is non-zero.