Unable to add WHERE conditions as OR to query object I'm attempting to override the query method for a node migration in the migrate_d2d module by adding two where conditions with "OR", and the first one is being added as AND instead of OR for some reason.  In this case, there is already one WHERE condition of node type, so I am adding two more, which means I'm trying to change

SELECT blah from {node} WHERE type = 'type1';


to

SELECT blah FROM {node} WHERE type IN ('type1', 'type2', 'type3');


It doesn't look like it is possible to override an existing WHERE condition without completely overriding the entire query method, so it seems that my next best bet is to add the WHERE conditions with OR so that the resulting query is 

SELECT blah FROM {node} WHERE (type = 'type1') OR (type = 'type2') OR (type = 'type3');


To accomplish this, based on what I've found searching around (such as here), I used db_or():

$db_or = db_or();
$db_or-&gt;condition('type', 'type2')
  -&gt;condition('type', 'type3');
$query-&gt;condition($db_or);


However, when I print out the resulting query what I actually get is

SELECT blah FROM {node} WHERE (type = 'type1') AND (type = 'type2') OR (type = 'type3');


and this is verified by the migration results, since the migration doesn't bring across any nodes (which makes sense, since one node can't be of two types).

I also tried it with separate additions to $db_or:

$db_or-&gt;condition('type', 'type2')
$db_or-&gt;condition('type', 'type3');


and even tried adding as one condition:

$db_or-&gt;condition('type', array('type2', 'type3'), 'IN');


but the result is still the same.

What it looks like to me is that no matter how you add a WHERE condition when there already is one, it automatically adds the next one as AND, even if you specify that it should be OR.

So my questions are:


Am I adding these conditions to the query object correctly (assuming I want them as OR)?
Is there a way to remove the initial condition so that I could just add my own WHERE condition from scratch?
Is there a better way to do this?


Thanks.
Am I adding these conditions to the query object correctly (assuming I want them as OR)?


Not quite; all components of the the OR need to be added to the condition object, so you need to do something like this:

$query = db_select('node')-&gt;fields('node', array('nid'));

$db_or = db_or();
$db_or-&gt;condition('type', 'type1')
  -&gt;condition('type', 'type2')
  -&gt;condition('type', 'type3');

$query-&gt;condition($db_or);


That'll give you this query string:

SELECT  node.nid AS nid
FROM 
{node} node
WHERE ( (type = :db_condition_placeholder_0) OR (type = :db_condition_placeholder_1) OR (type = :db_condition_placeholder_2) )



  Is there a way to remove the initial condition so that I could just add my own WHERE condition from scratch?


Yes you can use SelectQuery::where(), but there's really no need. You can use the above, or preferably...


  Is there a better way to do this?


Yes, by using IN as you originally planned:

$query = db_select('node')
  -&gt;fields('node', array('nid'))
  -&gt;condition('type', array('type1', 'type2', 'type3'), 'IN');


That gives:

SELECT  node.nid AS nid
FROM 
{node} node
WHERE  (type IN  (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) 


Note that the third parameter of "IN" to condition() isn't strictly necessary, as the DB class automatically assumes "IN" if an array is passed.