You are here

protected function SearchApiDbService::getTableAlias in Search API Database Search 7

Joins a field's table into a database select query.

Parameters

array $field: The field information array. The "table" key should contain the table name to which a join should be made.

SelectQueryInterface $db_query: The database query used.

bool $newjoin: (optional) If TRUE, a join is done even if the table was already joined to in the query.

string $join: (optional) The join method to use. Must be a method of the $db_query. Normally, "join", "innerJoin", "leftJoin" and "rightJoin" are supported.

Return value

string The alias for the field's table.

3 calls to SearchApiDbService::getTableAlias()
SearchApiDbService::createFilterCondition in ./service.inc
Creates a database query condition for a given search filter.
SearchApiDbService::getFacets in ./service.inc
Computes facets for a search query.
SearchApiDbService::setQuerySort in ./service.inc
Adds the query sort to a search database query.

File

./service.inc, line 1799
Contains SearchApiDbService.

Class

SearchApiDbService
Indexes and searches items using the database.

Code

protected function getTableAlias(array $field, SelectQueryInterface $db_query, $newjoin = FALSE, $join = 'leftJoin') {
  if (!$newjoin) {
    foreach ($db_query
      ->getTables() as $alias => $info) {
      $table = $info['table'];
      if (is_scalar($table) && $table == $field['table']) {
        return $alias;
      }
    }
  }
  return $db_query
    ->{$join}($field['table'], 't', 't.item_id = %alias.item_id');
}