Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using an attribute of a has_one relation as heading in Dataobjectmanager

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 536 Views
  • BartM
    Avatar
    Community Member
    9 Posts

    Using an attribute of a has_one relation as heading in Dataobjectmanager Link to this post

    Using an attribute of a has_one relation as heading in Dataobjectmanager

    Hello all,

    Once again I find myself using the DataObjectManager to build the necessary user-friendliness into my site and in general I am enjoying the experience. However, as usual, I seem to have run into this one small issue that I cannot seem to get my head around.

    Here's hoping one of you can help me out.

    The project I am currently working is fairly straightforward: a few pages explaining the goal and activities of the association that is our customer; and a couple of pages listing members and such for logged-in users.

    The page that is giving me trouble is a page listing the members of the direction. The DirectionPage has a has_many relation with the dataobject DirectionMember. DirectionMember in turn has a has_one relation to the DataObject Member.

    In the CMS the DirectionPage contains a DataObjectManager that shows all linked DirectionMembers, defined like this:

    $manager = new DataObjectManager(
       $this, // Controller
       'DirectionMembers', // Source name
       'DirectionMember', // Source class
       array(
          'Function' => 'Functie',
          'EmailAddress' => 'Emailadres'
       ), // Headings
       'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
       // Filter clause
       // Sort clause
       // Join clause
    );

    And this is the definition of DirectionMember:

    class DirectionMember extends DataObject
    {
       static $db = array (
          'EmailAddress' => 'Text',
          'Function' => 'Text'
    );

    static $has_one = array (
          'Member' => 'Member',
          'Parent' => 'DirectionPage'
    );
       
       public function getCMSFields_forPopup()
    {   
          $Group = DataObject::get_one("Group", "Title = 'WebsiteUsers'", "", "");
          $Members = $Group->Members(
                    $limit = '',
                    $offset = '',
                    '',
                    $sort = 'Member.Email',
                    $join = ''
                   );
          $dropdown = new DropdownField('MemberID','Lid',$Members->toDropdownMap('ID', 'Title', 'Selecteer lid'),$this->Member);
          
    return new FieldSet(
    new TextField('EmailAddress', 'Emailadres'),
             new TextField('Function', 'Functie'),
             $dropdown
    );
    }
    }

    Now, the above code works flawlessly... except that I would really like to show the DirectionMember's name as well as their function and email address. However, this name is stored inside the has_one field Member.
    I had hoped that I could do something like this:

    $manager = new DataObjectManager(
       $this, // Controller
       'DirectionMembers', // Source name
       'DirectionMember', // Source class
       array(
          'Member->Name' => 'Naam',
          'Function' => 'Functie',
          'EmailAddress' => 'Emailadres'
       ), // Headings
       'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
       // Filter clause
       // Sort clause
       

    However, no such luck. Am I missing anything obvious, or is getting this name more involved?

    Looking forward to your replies,
    Bart M.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using an attribute of a has_one relation as heading in Dataobjectmanager Link to this post

    Try Member.Name

    v--------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • BartM
    Avatar
    Community Member
    9 Posts

    Re: Using an attribute of a has_one relation as heading in Dataobjectmanager Link to this post

    Thank you very much, that did the trick. I already suspected it had to be something simple.

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