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

Filtering Pages on multiple many-many related DataObjects


Go to End


3 Posts   1853 Views

Avatar
Felicitas

Community Member, 16 Posts

9 April 2011 at 10:11pm

Hi,

I'm having problems with filtering Pages on their many-many related DataObjects.

I have a CompanyPage. Each CompanyPage has a many-many relation with four DataObjects (Levels, Products, Markets, Competences).

In the CompanyHolderPage I would like to have a combined filter for these DataObjects, where the user can choose a combination of levels, products, markets and competences and the output will be a list of the corresponding pages for which this is true.

Does any one have any example code or a hint in the right direction?

Thanks,

Felicitas

Avatar
swaiba

Forum Moderator, 1899 Posts

18 April 2011 at 7:09am

This is not the right way - but I've used it as it is quick and easy...

class MyModelAdmin_CollectionController extends ModelAdmin_CollectionController {
	function getSearchQuery($searchCriteria){
		$query = parent::getSearchQuery($searchCriteria);

		if ($this->modelClass == 'MyModel'){
			$query->where[] = ''; //ADD YOUR SQL HERE, using stuff from $searchCriteria
		}
	}
}

Avatar
Felicitas

Community Member, 16 Posts

27 April 2011 at 7:46pm

Thanks for your reply. Maybe this is the right direction. Right now I have four dropdown boxes, one for each dataobject, but not a combination of them.