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

Listing Many_Many objects - but with filters


Go to End


928 Views

Avatar
JonShutt

Community Member, 244 Posts

12 October 2011 at 4:19pm

Hi, I have a many_many relationship all working

in my template I can do this

<% control group %>
$Title
<% control people %>
$Title
<% end_control %>
<% end_control %>

this lists the group, and the people that have many_many relations to the group. simple

however, I need to filter both the group dataobject and the people dataobject.
the group just needs to be lists by sorted by Title, but the people need a search filter and sort.

I can create a function 'sortGroup' and use in place of just using 'group' in the template

public function sortGroup() {
return DataObject::get('Group', '', '`Title` ASC');
}

but i'm not sure how I would then create my filtered, sorted dataobject search to find all the many_many records within each group.
any ideas much appreciated.
thanks