Using “OR” conditions in CakePHP

Qualifying a query in CakePHP is as simple as adding conditions to the conveniently-named “conditions” array, like so:

// return array of all musicians
$all = $this->Musician->find('all');

// return array of all available reed players
$only_available_reeds = $this->Musician->find('all', array(
  'conditions' => array(
    'category' => 'reeds',
    'status' => 'available'
  )
));

If the array contains multiple conditions they will be joined using the boolean AND. Want to use OR instead? Add an OR subarray to “conditions”.

$available_reeds_or_brass = $this->Musician->find('all', array(
  'conditions' => array(
    'status' => 'available',
    'or' => array(
      'category' => 'reeds',
      'category' => 'brass'
    )
  )
));

This example uses both the AND and OR operators to narrow the search only to available reed or brass players.

Full documentation here.