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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Listing Many_Many objects - but with filters

Go to End



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 %>
<% control people %>
<% 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.