Adding a 'OR' condition to query I need to add a OR condition to my query so that I can get all nodes related to a particular term. Here is what I have done :

$query = \Drupal::database()-&gt;select('taxonomy_index', 'ti');
$query-&gt;fields('ti', ['nid']);

// OR CONDITION
$or_group = $query-&gt;orConditionGroup()-&gt;condition('ti.tid', $params[1], 'IN');

$query-&gt;condition('ti.tid', $params[0], 'IN');
$query-&gt;condition('ti.status', 1);

// Added OR CONDITION TO QUERY.
$query-&gt;condition($or_group);

$query-&gt;execute()-&gt;fetchAllAssoc('nid');


This is the how the query get build :


  QUERY
  
  SELECT ti.nid AS nid
  
  FROM {taxonomy_index} ti
  
  WHERE (ti.tid IN (:db_condition_placeholder_0))
  
  AND (ti.status = :db_condition_placeholder_1) 
  
  AND (ti.tid IN (:db_condition_placeholder_2));
  
  PARAMS
  
  Array (
  
  [:db_condition_placeholder_0] => 170
  
  [:db_condition_placeholder_1] => 1
  
  [:db_condition_placeholder_2] => 227
  
  );


As you can see the last "AND" condition should be "OR".

Thanks.
The solution seemed to be putting the explicit "IN" in the query, making the simplified version:

$entity_ids = $query
    -&gt;condition('attributes.color', array('red', 'green'), 'IN')
    -&gt;condition('attributes.building_type', 'bikeshed')
    -&gt;execute();