Skip to content
Snippets Groups Projects
Commit 4b505654 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2808333 by chx: Factor out the join from Tables.php

parent a491c499
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
namespace Drupal\Core\Entity\Query\Sql;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\Entity\Sql\TableMappingInterface;
......@@ -260,8 +261,7 @@ public function addField($field, $type, $langcode) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id);
// Add the new entity base table using the table and sql column.
$join_condition = '%alias.' . $entity_type->getKey('id') . " = $table.$sql_column";
$base_table = $this->sqlQuery->leftJoin($entity_type->getBaseTable(), NULL, $join_condition);
$base_table = $this->addNextBaseTable($entity_type, $table, $sql_column);
$propertyDefinitions = array();
$key++;
$index_prefix .= "$next_index_prefix.";
......@@ -367,4 +367,29 @@ protected function getTableMapping($table, $entity_type_id) {
return array_flip($mapping);
}
/**
* Add the next entity base table.
*
* For example, when building the SQL query for
* @code
* condition('uid.entity.name', 'foo', 'CONTAINS')
* @endcode
*
* this adds the users table.
*
* @param \Drupal\Core\Entity\EntityType $entity_type
* The entity type being joined, in the above example, User.
* @param string $table
* This is the table being joined, in the above example, {users}.
* @param string $sql_column
* This is the SQL column in the existing table being joined to.
*
* @return string
* The alias of the next entity table joined in.
*/
protected function addNextBaseTable(EntityType $entity_type, $table, $sql_column) {
$join_condition = '%alias.' . $entity_type->getKey('id') . " = $table.$sql_column";
return $this->sqlQuery->leftJoin($entity_type->getBaseTable(), NULL, $join_condition);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment