Jump to:

23487 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS3.1 - Problem with GridField one-to-one relationship

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 193 Views
  • dylangrech92
    Community Member
    17 Posts

    SS3.1 - Problem with GridField one-to-one relationship Link to this post

    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' );

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.