Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » GridField in GridField

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: 180 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    GridField in GridField Link to this post

    Hey guys,

    I want in SS3 something like the DOM in DOM from 2.4.

    I have an regular Page with a GridField

    class MyPage extends Page{
    static $has_many = array(
    'FooDataObjects' => 'FooDataObject'
    );

    public function getCMSFields(){
    $fields = parent::getCMSFields();
    $config = GridFieldConfig_RelationEditor::create();

    $foo = new GridField(
       'FooDataObjects',
       'FooDataObject',
       $this->FooDataObjects(),
       $config
       );
       $fields->addFieldToTab("Root.Foo", $foo);
    }
    }

    And now I want to set in the FooDataObject a second GridField:

    class FooDataObject extends DataObject{
    static $db = array(
             'Title' => 'Varchar(255)'
          );
          
          static $has_one = array(
             'MyPage' => 'MyPage'
          );
          
          static $has_many = array(
             'SecondFoos' => 'SecondFoo'
          );
          
          static $summary_fields = array(
          'Title'      
       );

       public function getCMSFields()
       {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab('Root.Main', new TextField('Title'), 'Content');
       
       $config = GridFieldConfig_RelationEditor::create();
       $secondFoo = new GridField(
                'SecondFoos',
                'SecondFoo',
                $this->SecondFoos(),
                $config    
       );
       $fields->addFieldToTab('Root.SecondFoo', $secondFoo);
    return $fields;
       }
    }

    class SecondFoo extends DataObject{
          static $db = array(
             'Title' => 'Varchar(255)',
             'Content' => 'Text'
          );
          
          static $summary_fields = array(
          'Title'      
       );
       
       static $has_one = array(
          'FooDataObject' => 'FooDataObject'
       );

       //Fields for the DOM Popup
       public function getCMSFields()
       {
       return new FieldSet(
          new TextField('Title'),
          new TextAreaField('Content')
       );
       }
       }

    But in this case a got this error: Couldn't run query: SELECT DISTINCT count(DISTINCT "SecondFoo"."ID") AS "0" FROM "SecondFoo" WHERE ("ParentID" = '0') Unknown column 'ParentID' in 'where clause'

    Does anyone know, what´s going wrong? Is it after all possible to use two GridFields like DOM in DOM?

    180 Views
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.