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 /

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

Complex search functionality


Go to End
Reply


533 Views

Avatar
jordanmk

Community Member, 3 Posts

21 March 2014 at 8:08pm

Edited: 21/03/2014 11:07pm

I have a class called Recipe as follows:

    class Recipe extends Page {
    
    	static $db = array(
    		"Title" => "Text"
    	);
    
    	static $many_many = array(
    		"RecipeTypes" => "RecipeType"
    	);
    }

And a class called RecipeType as follows:

    class RecipeType extends DataObject {
    	static $db = array(
    		"Title" => "Text",
    	);

    	static $belongs_many_many = array(
    		"Recipes" => "Recipe"
    	);
    }

For my site's search functionality, I want the search results to be every Recipe which has a Title that matches the search parameter, as well as every Recipe which has a RecipeType whose Title matches the search parameter.

I've tried the following:

    return Recipe::get()->filterAny(array(
    	'Title:PartialMatch' => $searchString,
    	'RecipeTypes.Title:PartialMatch' => $searchString
    ));

But that is only returning Recipes whose Title matches the search parameter; it's not returning any Recipes where one of the Recipe's RecipeTypes' Title property matches the search parameter.

Any ideas?