function Sql::adjustJoin
Same name in other branches
- 8.9.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::adjustJoin()
- 10 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::adjustJoin()
- 11.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::adjustJoin()
Fixes a join to adhere to the proper relationship.
The left table can vary based upon what relationship items are joined in on.
5 calls to Sql::adjustJoin()
- Sql::addRelationship in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Adds a relationship to the query.
- Sql::addTable in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Add a table to the query, ensuring the path exists.
- Sql::ensurePath in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Ensures the given table can be linked to the primary table in the JOINs.
- Sql::ensureTable in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Ensures a table exists in the queue.
- Sql::queueTable in core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php - Add a table to the query without ensuring the path.
File
-
core/
modules/ views/ src/ Plugin/ views/ query/ Sql.php, line 724
Class
- Sql
- Views query plugin for an SQL query.
Namespace
Drupal\views\Plugin\views\queryCode
protected function adjustJoin($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->view->storage
->get('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->leftTable != $this->relationships[$relationship]['table'] && $join->leftTable != $this->relationships[$relationship]['base'] && !isset($this->tables[$relationship][$join->leftTable]['alias'])) {
$this->ensureTable($join->leftTable, $relationship);
}
// First, if this is our link point/anchor table, just use the relationship
if ($join->leftTable == $this->relationships[$relationship]['table']) {
$join->leftTable = $relationship;
}
elseif (isset($this->tables[$relationship][$join->leftTable]['alias'])) {
$join->leftTable = $this->tables[$relationship][$join->leftTable]['alias'];
}
elseif (isset($this->tableQueue[$relationship]['alias'])) {
$join->leftTable = $this->tableQueue[$relationship]['alias'];
}
}
$join->adjusted = TRUE;
return $join;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.