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->condition('type', 'type2')
->condition('type', 'type3');
$query->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->condition('type', 'type2')
$db_or->condition('type', 'type3');
and even tried adding as one condition:
$db_or->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.