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 h开发者_JAVA技巧ow 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().
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()
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
精彩评论