Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Show related object title

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: 1165 Views
  • LesC
    Avatar
    Community Member
    70 Posts

    [SOLVED] Show related object title Link to this post

    Ok, so this should be my last question for today!

    I've managed to implement a relationship along with the DOM, but can't work out how to display the relationship in the admin page.

    I've got a NewsArticle object with four fields: Date, Author, News content, and Category.

    The Category is connected through a one -> many relationship (each article can have one category, category can have many articles).

    I've got the DOM to display just the Category ID that's been assigned to the NewsArticle object - but would like to display (and filter by category).

    Here's my code: http://pastie.org/590006

    Does anyone know what I need to do to get it working?

    Is there something basic I'm missing, or need to understand how the headers array can accept data?

    All help is much appreciated!

    L

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Show related object title Link to this post

    In your headings array, you should be able to do:

    array('NewsCategory.Title' => 'News category title');

    But if that doesn't work, just use a custom getter.

    getNewsCategoryTitle()
    {
    return $this->NewsCategory()->Title;
    }

    array('NewsCategoryTitle' => 'News category title');

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: [SOLVED] Show related object title Link to this post

    Hi Uncle Cheese,

    I feel like a bit of a dolt this afternoon, but how do I implement a custom getter?

    Does that need to be put in the header array, inside the getCMSFields function, or made as a function of its own in some way?

    I tried NewsContent.Title, and it just returned the id with a hash (pound) symbol in front of it...

    Cheers

    L

  • UncleCheese
    Avatar
    4085 Posts

    Re: [SOLVED] Show related object title Link to this post

    You put the custom getter in the model for the class you're viewing in the DOM. In your case, that's NewsArticle, I believe.

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: [SOLVED] Show related object title Link to this post

    Thanks for your help on this Uncle Cheese!

    It's all working just as I need it to

    I'll make a post with my final code so others can share at somepoint this weekend.

    L

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