Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

GridField in GridField


Reply


383 Views

Avatar
Bereusei

Community Member, 94 Posts

28 June 2013 at 9:22pm

Edited: 28/06/2013 9:24pm

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?