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.

Data Model Questions /

Get Relation on data durung onBeforeWrite (first time) [SOLVED]


Reply


5 Posts   610 Views

Avatar
zenmonkey

Community Member, 528 Posts

2 May 2012 at 1:32pm

I have a dataobject in which I need relation data for a function on the first onBeforeWrite. The relation is set with DropdownField populated with a toDropdownMap in the CMS. In theory I should be able pull the ID from that form element but I'm not sure how its passed to the onBeforeWrite function. Calling $this->RelatedDataObejct doesn't work because that relation isn't set yet. And I can't get the form Value with $this->getField();

I could call the function I need in onAfterWrite and only fire it if the value I'm creating is null and putting another write function in it but that just seems like a recipe for disaster with potential write loops

Any ideas?

Avatar
swaiba

Forum Moderator, 1799 Posts

2 May 2012 at 7:56pm

If it is a has_one then $this->RelationNameID should work

Avatar
zenmonkey

Community Member, 528 Posts

3 May 2012 at 12:56am

The relation is still null at onBeforeWrite the first time. It doesn't get created until the actual write. I'm talking about the initial creation of the record

Avatar
swaiba

Forum Moderator, 1799 Posts

3 May 2012 at 12:59am

can you do a var_dump of $this and check for anything that matches the relationship?

we are talking a has_one relationship right?

Avatar
zenmonkey

Community Member, 528 Posts

3 May 2012 at 12:49pm

I got fixed, the DataObject in question was an extension of DataObjectAsPage so I wrapped the functions in my onBeforeWrite in a if($this->ID !=0). I'll post that it needs to be documented