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.

Data Model Questions /

Listing Many_Many objects - but with filters


Reply


430 Views

Avatar
Futureweb

Community Member, 233 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