Hi,
I have a DataObject (A) in ModelAdmin that's supposed to save data to a record on another DataObject (B) in an onBeforWrite-method.
But if I'm adding a new DataObjectA, it doesn't save to one record, but to two records on DataObjectB...
Does someone know what's happening here and how to solve this?
Below is the structure:
class DataObjectA extends DataObject{
static $db = array(
"titleA" => "Varchar",
);
static $has_many = array(
"DataObjectB" => "DataObjectB",
);
public function onBeforeWrite() {
$myDataObjectB = new DataObjectB();
$myDataObjectB->titleB = "NewTitle";
$myDataObjectB->write();
parent::onBeforeWrite();
}
class DataObjectB extends DataObject{
static $db = array(
"titleB" => "Varchar",
);
static $has_one = array(
"DataObjectA" => "DataObjectA"
);
}
BTW If DataObjectA exists and you click save, it will save just one new record on DataObjectB