2

i'm trying to alter drupal view-2 query, basically want to add one more table. I'm able to alter the where clause of query using hook_views_query_alter() but don't know how to join one more table.

function module_views_query_alter(&$view, &$query) {
        if ($view->name == 'view1_name') {
                $query->where[0]['args'][] = 'SOMETEXT';
                $query->where[0]['clauses'][] = "QUERY";
        }

        if($view->name = 'view2_name'){
              $query->table_queue['content_type_sold_product'];
              $query->tables['content_type_sold_product'];
        }
    }

Why do i want to do this - if relationship tab is available in view that is used to join the table, but in my case table which i want to join contains the field that is not a node-reference however field name and its value matches with one of the view table table.

Does anyone know how to perform JOIN in views_query_alter().

2 Answers 2

2

Seems there are two different ways you can do this, see these links:

Adding a JOIN statement in hook_views_query_alter()

Add Table Join, Where, and Order By to Views Query in views_query_alter()

Sign up to request clarification or add additional context in comments.

Comments

2

Giving Answer to own question

fortunately i found these links

http://drupalmodules.com/module/reverse-node-reference module enhances views with reverse relationships for node reference fields.

you may also need http://drupal.org/project/noderelationships

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.