Adding a JOIN statement to hook_views_query_alter ()

I need to change the request. Views are generated so that I can use very custom filters. I implemented the add_where () function with some ORs thanks to this question: OR operator in Drupal view filters

However, this solves only part of my problem. There are several fields that I cannot filter because I need to have extra JOINs in my request.

Is there something along the lines

$view->query->add_where()

which can insert JOIN statements?

+3
source share
2 answers

, $view->query->add_table() $view->query->add_relationship() ( views_query 'includes/query.inc'), , ( , ).

, Views, , .


(: , , :/

+2

. :

function hook_views_query_alter(&$view, &$query) {
    $join = new views_join();
    $join->table = 'my_table';
    $join->field = 'my_field';
    $join->left_table = 'left_table';
    $join->left_field = 'left_field';
    $join->type = 'left';
    $join->extra = array(
        array(
            'field' => 'bundle',
            'value' => 'user',
        )
    );
    $query->add_relationship('relationship_name', $join, 'node');
}
+5

Source: https://habr.com/ru/post/1752119/


All Articles