I have two classes which I want to have a one-to-one relationship between them and be able to manage everything through GridField however GridField throws an error: [User Error] Uncaught LogicException: GridField doesn't have a modelClassName, so it doesn't know the columns of this grid.
These are my classes:
// Channel Page
class ChannelPage extends Page{
private static $can_be_root = false;
private static $has_one = array( 'Image' => 'Photo' );
public function getCMSFields(){
$fields = parent::getCMSFields();
$config = GridFieldConfig_RelationEditor::create();
$config->getComponentByType( 'GridFieldDataColumns' )->setDisplayFields( array(
'Name' => 'Name',
'Description' => 'Description'
) );
$fields->addFieldToTab( 'Root.Image', new GridField( 'Image', 'Image', $this->Image(), $config ) );
return $fields;
}
}
// PhotoDecorator
class PhotoDecorator extends DataExtension{
static $has_one = array(
'IndexPage' => 'IndexPage',
'ChannelPage' => 'ChannelPage'
);
public function updateCMSFields( FieldList $fields ){
$fields->removeByName( 'IndexPageID' );
$fields->removeByName( 'ChannelPageID' );
}
}
// Photo
class Photo extends DataObject{
private static $db = array(
'Name' => 'VARCHAR(255)',
'Description' => 'Text'
);
private static $has_one = array( 'Image' => 'Image' );
}