Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By xSDx on
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
Join
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.
Doing Relationships in Views
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(...);
}
}