Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Many-many relationship between two page objects

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1179 Views
  • sonet
    Avatar
    Community Member
    33 Posts

    Many-many relationship between two page objects Link to this post

    Hello...

    I have tour and place page objects. I would like to have on a tour page places appear in order. By clicking on the place one should get to the place page, which shows all tours going through this place.

    I was able to establish the many-many relationship between this two page objects by:

    Tour.php

    class Tour extends Page {

       static $many_many = array(
          'Places' => 'Place'
       );

       function getCMSFields() {

             $fields = parent::getCMSFields();

             $placesTablefield = new ManyManyComplexTableField($this,'Places','Place',
                 array('Name' => 'Name'),'getCMSFields');
             //$placesTablefield->setAddTitle('A Place');

             $fields->addFieldToTab('Root.Content.Places', $placesTablefield);
             return $fields;
       }
    }

    Place.php

    class Place extends Page {

       static $db = array(
             'Name' => 'Text'
       );

       static $belongs_many_many = array(
             'Places' => 'Place'
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', new TextField('Name'), 'Name');
          return $fields;
       }

    }

    1) I am using an additional field to show up in the CMS Places tab 'name'. How can I reference the place page name itself?

    2) How can I prevent the 'Add' link showing up within the CMS Places Tab?

    3) I need to have an additional numeric field in the Tour_Places table which will allow an ORDER BY. Can this be accomplished?

    If so, a push in the right direction would be REALLY helpful. Thanks a lot.

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Many-many relationship between two page objects Link to this post

    to answer question #2 (disable the 'add' button), add this line of code after you create the complextablefield:

    $yourtable->setPermissions(array('delete', 'edit'));


    (i got the answer from http://www.silverstripe.com/website-authors-forum/flat/76012)

    i'd love to see answers for question #1 and #3 as well.

    -Chris

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