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.

Customising the CMS /

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

[Solved] Adding Custom Fields to Summary_fields


Go to End


6 Posts   9689 Views

Avatar
cumquat

Community Member, 201 Posts

12 April 2011 at 10:47pm

Hi ya,

Ok got a weird one here, I'm trying to add some fields to the summary_fields list so that i can see them in Model Admin and i'm getting an 'Uncaught Exception: Unable to traverse to related object field [NiceTime] on [Course]' error.

Now the weird bit, if i upload the code and don't refresh the browser it all works fine, the moment i refresh i get the error now i'm sure my code is correct, please tell me if I'm wrong.

static $db = array(
      'DateTaken' => 'Date'
	  
   );
static $summary_fields = array(
        	'Skill.Title' => 'Skill',
		'NiceTime' => 'Date Passed',
	);
public function getNiceTime() { 
	return $this->obj('DateTaken')->Nice(); 
}

This is just a simple function there is another function i want to use which calculates the expiry date of a course which also doesn't work, same error so is this a bug or am i being an idiot?

Hope someone can help, oh this is on 2.4.5.

Mick

Avatar
cumquat

Community Member, 201 Posts

14 April 2011 at 8:54pm

**BUMP***

Anyone, is my code right, or has anyone had similar problems passing functions to the summary_fields?

Mick

Avatar
ajshort

Community Member, 244 Posts

14 April 2011 at 9:13pm

By default the summary fields definition is also used for the searchable fields. Since searchable fields can only operator on fields that actually exist in the DB, it's erroring out. You'll need to define a separate searchable_fields on your object without the NiceTime field.

Avatar
cumquat

Community Member, 201 Posts

14 April 2011 at 10:13pm

That was it...

many thanks for that, much appreciated.

Mick

Avatar
Muaddib

Community Member, 4 Posts

17 October 2013 at 1:24am

It was really helpfull.

Avatar
Spambanjo

Community Member, 24 Posts

22 October 2013 at 9:30pm

Thanks for this. Ajshort's solution was the fix for my problem too.