Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Complex search functionality

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

Page: 1
Go to End
Author Topic: 225 Views
  • jordanmk
    Community Member
    2 Posts

    Complex search functionality Link to this post

    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?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.