Hi Guys,
I am having problems understanding how to manage objects that relate to a has_one relationship when they are extended example:
Note I am using Grid Field Extensions (https://github.com/silverstripe-australia/silverstripe-gridfieldextensions) to allow the adding of the extended classes this way each time one is added I can have a different fields...
class Item extends DataObject {
private static $has_one = array(
'Type' => 'ItemType',
);
private static $belongs_to = array(
'ItemTypes' => 'ItemType',
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$gridConfig = GridFieldConfig_RelationEditor::create();
$dataList = ItemType::get()->filter(array('ID'=>$this->Type()->ID));
$gridField = GridField::create('TypeID', 'Type', $dataList, $gridConfig);
$gridField->getConfig()
->removeComponentsByType('GridFieldAddNewButton')
->removeComponentsByType('GridFieldAddExistingAutocompleter')
->addComponent(new GridFieldAddNewMultiClass());
$fields->addFieldToTab('Root.Type', $gridField);
}
}
class ItemType extends DataObject {
private static $has_many = array(
'Items' => 'Item'
);
}
class MyType extends ItemType {
private static $db = array(
'SomeField' => "Text",
);
}
class AnotherType extends ItemType {
private static $db = array(
'AnotherField' => "Text",
);
}
This all *seems* to work the problem is that it only allows one extended Type to be added if you add another of the same tClassName (ItemType) the same record gets updated in the extended table as its ID is the same as the ItemType->ID.
What am I missing here?
Any help greatly appreciated!