Search code examples
phpmysqldrupaldrupal-6

drupal view2 views_query_alter for JOIN


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().


Solution

  • 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