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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

ComplexTableField not getting related object values


Go to End


2178 Views

Avatar
ScottiouS

Community Member, 54 Posts

10 July 2008 at 12:39pm

Edited: 10/07/2008 12:40pm

I have a complextablefield in the backend CMS. This pagetype has a has_many relation to a DataObject. This DataObject has a has_one relation to a groupID.

The idea is to display the list of objects related to the particular page (which works nicely) and also show which Group each object belongs to. I can show the GroupID but that doesn't mean much to the end user. So in an attempt to show the Group.Title I have tried accessing Group.Title but this returns an SQL error as it does not fetch the Group table. I also Tried the following...

On the RepositoryPage.php:

function getCMSFields() {
      $fields = parent::getCMSFields();
 
      $tablefield = new HasManyComplexTableField(
         $this,
         'GBFiles',
         'GBFile',
         array(
			'Name' => 'File Name',
			'FileSize' => 'File Size',
			'GroupTitle' => 'Group Restriction'
         ),
         'getCMSFields_forPopup',
         "GBFile.MyRepositoryPageID = {$this->ID}" // Source filter (WHERE clause in SQL) 
      );
      $tablefield->setAddTitle( 'a file' );
	  
      $tablefield->relationAutoSetting = true;

      $fields->addFieldToTab( 'Root.Content.Files', $tablefield );
 
      return $fields;
   }

And then on the object itself:

	function getGroupTitle() {
		//return $this->Group->Title();
		return "widget group";
	}

This "should" currently return "widget group" for each row of the table but it returns nothing. It does however pickup the function is there becuase if I remove this function I get an error.

What I am missing here?