1 views_plugin_query_default.inc views_plugin_query_default::adjust_join($join, $relationship)

Fix a join to adhere to the proper relationship; the left table can vary based upon what relationship items are joined in on.

File

core/modules/views/plugins/views_plugin_query_default.inc, line 671
Defines the default query object.

Class

views_plugin_query_default
Object used to create a SELECT query.

Code

function adjust_join($join, $relationship) {
  if (!empty($join->adjusted)) {
    return $join;
  }

  if (empty($relationship) || empty($this->relationships[$relationship])) {
    return $join;
  }

  // Adjusts the left table for our relationship.
  if ($relationship != $this->base_table) {
    // If we're linking to the primary table, the relationship to use will
    // be the prior relationship. Unless it's a direct link.

    // Safety! Don't modify an original here.
    $join = clone $join;

    // Do we need to try to ensure a path?
    if ($join->left_table != $this->relationships[$relationship]['table'] && 
      $join->left_table != $this->relationships[$relationship]['base'] && 
      !isset($this->tables[$relationship][$join->left_table]['alias'])) {
      $this->ensure_table($join->left_table, $relationship);
    }

    // First, if this is our link point/anchor table, just use the relationship
    if ($join->left_table == $this->relationships[$relationship]['table']) {
      $join->left_table = $relationship;
    }
    // then, try the base alias.
    elseif (isset($this->tables[$relationship][$join->left_table]['alias'])) {
      $join->left_table = $this->tables[$relationship][$join->left_table]['alias'];
    }
    // But if we're already looking at an alias, use that instead.
    elseif (isset($this->table_queue[$relationship]['alias'])) {
      $join->left_table = $this->table_queue[$relationship]['alias'];
    }
  }

  $join->adjusted = TRUE;
  return $join;
}