Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS3 has_many relations

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

Page: 1
Go to End
Author Topic: 462 Views
  • zenmonkey
    Avatar
    Community Member
    524 Posts

    SS3 has_many relations Link to this post

    I'm having a little trouble understanding how the new GridField replaces some of the old interfaces. I'm trying to manage a $has_many relation on a page but when I create a new record using the GridField it doesn't automatically create the relation (just shows a drop down)

    My DataObject Looks like this

    class FAQ extends DataObject {

       

       static $db = array(
          'Question' => 'Varchar',
          'Answer' => 'HTMLText'
       );
       
       static $has_one = array (
          'FaqPage' => 'FaqPage'
       );
       
       static $summary_fields = array(
          'Question' => 'Question',
          'Answer' => 'Answer'
       );   

       
    }


    and the page looks like

    class FaqPage extends Page {

       /**
        * Static vars
        * ----------------------------------*/
       
       static $description = 'Holds Frequently Asked Questions';

       /**
        * Data model
        * ----------------------------------*/

       static $has_may = array (
          'FAQs' => 'FAQ'
       );      

       /**
        * Common methods
        * ----------------------------------*/

        public function getCMSFields() {
          
           $fields = parent::getCMSFields();
          
           $FAQ = FAQ::get()->filter(array('FaqPageID' => $this->ID));
          
           $FAQField = new GridField("FAQs", "Frequently Asked Question", $FAQ, GridFieldConfig_RelationEditor::create());
          
          
          
           $fields->addFieldToTab("Root.FAQs",$FAQField);
          
           return $fields;
          
        }

       
    }


    Not sure what I'm missing and the documentation doesn't appear to be clear

    Thanks

    462 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.