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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

[SOLVED] Show related object title


Go to End


5 Posts   1756 Views

Avatar
LesC

Community Member, 70 Posts

21 August 2009 at 5:00am

Edited: 21/08/2009 9:48pm

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

21 August 2009 at 5:16am

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');

Avatar
LesC

Community Member, 70 Posts

21 August 2009 at 5:21am

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

21 August 2009 at 5:38am

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.

Avatar
LesC

Community Member, 70 Posts

21 August 2009 at 9:48pm

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