I want to do a conditional relationship (JOIN) in views. Can someone please explain how to do this. There is no option that I know it in UI. So maybe somehow in hook_views_query_alter or ...?

Comments

edward.radau’s picture

What sort of join do you have in mind? What exactly are you trying to accomplish? Generally when you add extra fields or filter by certain values Views does this for you.

slewazimuth’s picture

Quick reference:

https://www.acquia.com/blog/drupal-views-sql-analogy-easier-way-explain-...

To do stuff directly yourself:

function mymodule_views_pre_execute(view &$view) {
if ($view->name == 'view_to_modify') {
$query = $view->build_info['query'];
$count_query = $view->build_info['count_query'];
$query->condition(...);
$query->addJoin(...);
$count_query->condition(...);
}
}