1.20.x select.inc public SelectQuery::addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = array())

Implements SelectQueryInterface::addJoin().

Overrides SelectQueryInterface::addJoin

File

includes/database/select.inc, line 1555

Class

SelectQuery
Query builder for SELECT statements.

Code

public function addJoin($type, $table, $alias = NULL, $condition = NULL, $arguments = array()) {

  if (empty($alias)) {
    if ($table instanceof SelectQueryInterface) {
      $alias = 'subquery';
    }
    else {
      $alias = $table;
    }
  }

  $alias_candidate = $alias;
  $count = 2;
  while (!empty($this->tables[$alias_candidate])) {
    $alias_candidate = $alias . '_' . $count++;
  }
  $alias = $alias_candidate;

  if (is_string($condition)) {
    $condition = str_replace('%alias', $alias, $condition);
  }

  $this->tables[$alias] = array(
    'join type' => $type,
    'table' => $table,
    'alias' => $alias,
    'condition' => $condition,
    'arguments' => $arguments,
  );

  return $alias;
}