Jump to:

5121 Posts in 1527 Topics by 1119 members

Customising the CMS

SilverStripe Forums » Customising the CMS » [Solved] Adding Custom Fields to Summary_fields

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1325 Views
  • cumquat
    Avatar
    Community Member
    163 Posts

    [Solved] Adding Custom Fields to Summary_fields Link to this post

    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

  • cumquat
    Avatar
    Community Member
    163 Posts

    Re: [Solved] Adding Custom Fields to Summary_fields Link to this post

    **BUMP***

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

    Mick

  • ajshort
    Avatar
    Community Member
    239 Posts

    Re: [Solved] Adding Custom Fields to Summary_fields Link to this post

    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.

  • cumquat
    Avatar
    Community Member
    163 Posts

    Re: [Solved] Adding Custom Fields to Summary_fields Link to this post

    That was it...

    many thanks for that, much appreciated.

    Mick

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