Hi,
I´m trying to set initial values on a DataObject using a DataObjectDecorator. After creating the owner-object the value is still empty.
In detail I extended the SiteTree with an custom Object:
...
function extraDBFields() {
return array(
'has_one' => array(''MyObject","MyObject");
);
}
...
In the same class, I override the method populateDefaults:
function populateDefaults() {
$myO = DataObject::get_by_id("MyObject", 1); //this Object with ID=1 exists in db!
$this->owner->MyObject = $myO;
}
After creating a new SiteTree-item the attribute MyObjectID in the db-table SiteTree contains a 0 (zero). I tried
$item->owner->write();
in populateDefaults too, but this created a second SiteTree-item without the correct MyObjectID too.
Without any success in using the DataObjectDecorator I tried another, second solution. I extended CMSMain (in the same way as LeftAndMainDecorator does) and set the attribute on the reference parameter &$item in the function augmentNewSiteTreeItem(&$item). Without success too. The resulting attribute MyObjectID in my SiteTree-item is still 0.
I verified both method-calls with debug-statements - both extensions itself worked correctly.
Is there any other initialization after these both extension-calls which overwrites the has_one-relation?
Best regards,
chrclaus