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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

write() - Method on Field of Subclass of $has_many - DataObject

Go to End

2 Posts   1082 Views


Community Member, 17 Posts

17 December 2011 at 5:41am


i got that following setup:

Page-Class width 2 $has_many relations, to: lets say "Customer"- and "CustomerPremium"- DataObjects.
My CustomerPremuim - Class is a direct Subclass of Customer.

Now i want an db-write - operation (update a Field) on each related CustomerPremium DataObject in that onAfterWrite() - Method on the Page-Class.

If i target the Parent-Class "Customer" with "$this->Customer()" the write() Method works, but not on the Subclass.
Even since the Subclass has its own $has_many relation in Page.

Any Idea why is that? :(

if i print out the result of the iteration i get my regular DataObjects in any case. So i'm wondering that i cant write to it just because
its an Subclass.

my code is:
class Page extends .... {

$has_many {
"Customers" => "Customer",
"CustomersPremium" => "CustomerPremium"

function onAfterWrite(){
foreach($this->CustomerPremium() as $i) {
$i->Format = "482 x 288";





Community Member, 17 Posts

19 December 2011 at 3:58am

Ok, my Problem seems to be solved.
After min. 5 Hours walking down the wrong way I figured out that my Eventhandler onAfterWrite has to be changed in onBeforeWrite...