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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Using an attribute of a has_one relation as heading in Dataobjectmanager


Reply


3 Posts   649 Views

Avatar
BartM

Community Member, 9 Posts

26 January 2012 at 3:41am

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.

Avatar
UncleCheese

Forum Moderator, 4096 Posts

26 January 2012 at 6:59am

Try Member.Name

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

Avatar
BartM

Community Member, 9 Posts

26 January 2012 at 8:39pm

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