secuaz
secuaz

Reputation: 479

Silverstripe sql debug

How can I use OR with filter method e.g:

    $entries = BookstoreBook::get()
    ->filter(array(
    'Title:PartialMatch' => $searchString
    ));)

Field:PartialMatch is the way I found to use LIKE for string matching.

Upvotes: 2

Views: 348

Answers (2)

Mia
Mia

Reputation: 1

You can use FilterAny for OR:

$objects = $Object::get()->filterAny(array("Title"=>"Something","ID"=>"SomethingElse"));

You would also use a where if you HAD to:

$objects = $Object::get()->where("Title='Something' OR ID='SomethingElse'");

The relationship call also includes a where in the first parameter:

$objects = $Object::get("Title='Something' OR ID='SomethingElse'");

Any lastly, you can do a filter + a where, if you needed to, in some weird "I dont think youll ever find" situation:

$objects = $Object::get()->filter(array())->where();

;)

Upvotes: 0

colymba
colymba

Reputation: 2644

what about:

$entries = BookstoreBook::get()
  ->filter(array(
    'Title:PartialMatch' => array($searchString, $anotherString)
  ));

Upvotes: 2

Related Questions