Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Show only related objects

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1859 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: Show only related objects Link to this post

    Here's a random shot in the dark..

    $fields->addFieldToTab("Root.Content.Students", new LiteralField('list', $this->getManyManyComponents('Students')->UL()));

    No idea if that will work, but worth a shot!

  • Foldor
    Avatar
    Community Member
    4 Posts

    Re: Show only related objects Link to this post

    Sorry for necroposting, but i had the same need to show only related objects. I have many EventPages and many Members. Each of members can be assigned to each EventPage, but there are about 1,000 users and usually about 200-300 are assigned. So I did the next:

    EventPage.php:

    class EventPage extends Page
    {
    .
    .
    static $many_many = array(
          'Members' => 'Member'
       );

    public function getCMSFields() {
        $fields = parent::getCMSFields();
          
          $sqlQuery = new SQLQuery();
          $sqlQuery->select = array('MemberID');
          $sqlQuery->from = array("EventPage_Members");
          $sqlQuery->where = array("EventPageID=".$this->ID);
          $rawSQL = $sqlQuery->sql();
          $result = $sqlQuery->execute();
          $query="MemberID=";
          foreach($result as $row){
             $query .= $row[MemberID]." OR MemberID=";
          }
          $query .= $row[MemberID];
          
          
          $modulesTablefield = new ManyManyComplexTableField(
    $this,
    'Members',
    'Member',
    array(
           'Name' => 'Name',
        'Email' => 'Email'
    ),
    'getCMSFields_forPopup',
           $query,
           '',
           ''
    );

    $modulesTablefield->setReadOnly('true');

    $fields->addFieldToTab( 'Root.Content.Subscribers', $modulesTablefield );

          return $fields;
       }
    .
    .
    }

    In Member.php from sapphire i also made some changes like
    static $belongs_many_many = array(
    'Events' => 'EventPage'
    );

    What is my code doing? It takes all MemberID which are related to the current EventPage from many_many table which in my case named EventPage_Members and had columns MemberID, EventPageID. Then I made a $query with that MemberIDs which is used as filter in ManyManyComplexTableField constructor.

    This solves only one half of problem - i couln't remove that markers... Hope others could =)

  • UncleCheese
    Avatar
    4085 Posts

    Re: Show only related objects Link to this post

    I'm actually just about to release a bunch of new features for MMDOM, and one of them is a "related objects only" checkbox. I don't know if that will help you or not.

    1859 Views
Page: 1 2
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.