Commit 4b505654 authored by alexpott's avatar alexpott

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

parent a491c499
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment