I'm transferring SQL statements from a Drupal 5 installation to Drupal 8, and struggling with And/Or condtions. eg given the original SQL:
SELECT ..... WHERE ..... AND classes.description = "Photographer" AND (classoptions.description = "Name of photographer here" OR classoptions.description = "Not assigned"). I've translated it to:
$query = $this->dbConnection->select('classes'); ....etc.... $query->condition('classes.description', 'Photographer'); So far, so good. Then I need an OR condition for
$query->condition('classoptions.description', 'Name of photographer here'); $query->condition('classoptions.description', 'Not assigned'); Looking at documentation on-line, using db_or() is suggested, as in :
$query->condition(db_or() ->condition('classoptions.description', 'Name of photographer here'); ->condition('classoptions.description', 'Not assigned')); ..but this is a) deprecated, b) gives error 'db_or function not found' The replacement for db_or() is to obtain a new Condition object, but what am I supposed to do with it? The function
$query->orConditionGroup(); Will return a new Condition object, and the code
$query->condition(orConditionGroup() ->condition('classoptions.description', 'Name of photographer here'); ->condition('classoptions.description', 'Not assigned')); Formats a Condition object with the conditions to be ORed just fine.But again, how do I incorporate this into the query?