Change record status: 
Project: 
Introduced in branch: 
8.4.x
Introduced in version: 
8.4.0-rc2
Description: 

A new helper method addNextBaseTable is added to \Drupal\Core\Entity\Query\Sql\Tables. This factors out the relationship entity table join into a method so contrib modules can add different column for JOINs than the column used in field storage.

For example in dynamic_entity_reference the sql_column is changed like this.

  /**
   * {@inheritdoc}
   */
  protected function addNextBaseTable(EntityType $entity_type, $table, $sql_column) {
    // Parent method is overridden in order to choose the correct column to
    // join on (string or int).
    $entity_type_id_key = $entity_type->getKey('id');
    if ($entity_type_id_key !== FALSE) {
      if (DynamicEntityReferenceItem::entityHasIntegerId($entity_type->id())) {
        $sql_column .= '_int';
      }
    }
    return parent::addNextBaseTable($entity_type, $table, $sql_column);
  }

To make the Tables::addNextBaseField() more usable in #2908605: Pass field storage to Tables::addNextBaseField() a new parameter $field_storage is add to the function in 8.4.x before 8.4.0-rc2.
After (8.4.0-rc2):

  /**
   * {@inheritdoc}
   */
  protected function addNextBaseTable(EntityType $entity_type, $table, $sql_column) {
    $field_storage = func_get_arg(3);
    // Parent method is overridden in order to choose the correct column to
    // join on (string or int).
    $entity_type_id_key = $entity_type->getKey('id');
    if (($field_storage->getType() === 'dynamic_entity_reference') && ($entity_type_id_key !== FALSE)) {
      if (DynamicEntityReferenceItem::entityHasIntegerId($entity_type->id())) {
        $sql_column .= '_int';
      }
    }
    return parent::addNextBaseTable($entity_type, $table, $sql_column);
  }

After (8.5.0-aplha1):

  /**
   * {@inheritdoc}
   */
  protected function addNextBaseTable(EntityType $entity_type, $table, $sql_column, FieldStorageDefinitionInterface $field_storage) {
    // Parent method is overridden in order to choose the correct column to
    // join on (string or int).
    $entity_type_id_key = $entity_type->getKey('id');
    if (($field_storage->getType() === 'dynamic_entity_reference') && ($entity_type_id_key !== FALSE)) {
      if (DynamicEntityReferenceItem::entityHasIntegerId($entity_type->id())) {
        $sql_column .= '_int';
      }
    }
    return parent::addNextBaseTable($entity_type, $table, $sql_column);
  }
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done