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.

Data Model Questions /

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

Many Many Relationship -> get just one category


Go to End


2 Posts   1740 Views

Avatar
StarForce

Community Member, 11 Posts

8 November 2010 at 4:51am

Hi

i´ve created a many-many relationship (news <-> category)

when using this code, i get all news:

$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsPage", "ParentID = $news->ID", "Datum DESC", "", $num) : false;,

what do i have to do, to just get all news for one category?

Thanks :)

StarForce

Avatar
baba-papa

Community Member, 279 Posts

13 November 2010 at 8:52am

if the relation on category is called "news" you can simply call the related objects like:

$category->news()