1 views_handler_relationship.inc views_handler_relationship::query()

Called to implement a relationship in a query.

File

core/modules/views/handlers/views_handler_relationship.inc, line 108
Views' relationship handlers.

Class

views_handler_relationship
Simple relationship handler that allows a new version of the primary table to be linked in.

Code

function query() {
  // Figure out what base table this relationship brings to the party.
  $table_data = views_fetch_data($this->definition['base']);
  $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];

  $this->ensure_my_table();

  $def = $this->definition;
  $def['table'] = $this->definition['base'];
  $def['field'] = $base_field;
  $def['left_table'] = $this->table_alias;
  $def['left_field'] = $this->real_field;
  if (!empty($this->options['required'])) {
    $def['type'] = 'INNER';
  }

  if (!empty($this->definition['extra'])) {
    $def['extra'] = $this->definition['extra'];
  }

  if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
    $join = new $def['join_handler'];
  }
  else {
    $join = new views_join();
  }

  $join->definition = $def;
  $join->options = $this->options;
  $join->construct();
  $join->adjusted = TRUE;

  // use a short alias for this:
  $alias = $def['table'] . '_' . $this->table;

  $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);

  // Add access tags if the base table provide it.
  if (empty($this->query->options['disable_sql_rewrite']) && isset($table_data['table']['base']['access query tag'])) {
    $access_tag = $table_data['table']['base']['access query tag'];
    $this->query->add_tag($access_tag);
  }
}