1

I'm doing a hook_views_query_alter and trying to add a simple OR condition to the end of the existing WHERE clause. I'm using set_group_operator('OR') but when I examine the actual query in the MySQL logs, it still has an AND.

Here's my code:

function mymodule_views_query_alter(&$view, &$query) {
  $display_title = $view->display[$view->current_display]->display_title;
  if ($view->name == 'events' && stristr($display_title, "event")) {
    $query->set_where_group('AND', 'repeating', 'where');
    $query->add_where('repeating', 'node.type', 'event', '=');
    $query->set_group_operator('OR');
  }
}

What I'm seeing in the actual query is:

WHERE (( (node.type = 'event') )
AND ( ___STUFF_THAT_WAS_ALREADY_IN_THE_WHERE_CLAUSE___ )

When what I want/expect would be:

WHERE (( (node.type = 'event') )
OR ( ___STUFF_THAT_WAS_ALREADY_IN_THE_WHERE_CLAUSE___ )

What am I doing wrong? Any suggestions? I'm kinda stumped.

Thanks

  • Long shot, so not submitting as an answer: Is this function located in mymodule.module (as opposed to a .inc) ? If not, try moving it to mymodule.module and flushing your cache. – jdu Jan 8 '14 at 19:42
  • Thanks for the idea. It's in my main module and I've flushed the cache several times. I see the effects of other things I change (e.g., I can change the field name in the WHERE clause and observe that changing in the query log). It's just this darn set_group_operator that isn't working. As a further data point, if I do a dprint_r($query) I can see that the group operator, as shown in the array/class, is in fact OR, but when the query shows up in the MySQL log, I see an AND. – mlevin Jan 8 '14 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.