Omitting the base_table from an entity type works with the storage, but not with queries

Created on 1 October 2020, about 4 years ago
Updated 27 August 2024, 4 months ago

Problem/Motivation

If you omit the base_table from an entity type annotation, then storage operations such as load and save still work.

But queries crash.

This is because DefaultTableMapping assumes the base table if the entity type doesn't define it:

    $this->baseTable = $this->prefix . $entity_type->getBaseTable() ?: $entity_type->id();

but Sql\Query doesn't:

      if (!$base_table = $this->entityType->getBaseTable()) {
        throw new QueryException("No base table for " . $this->entityTypeId . ", invalid query.");
      }

Steps to reproduce

Remove the base_table from an entity type.
Clear caches.
Load and save still work, but something requiring a query does not.

Proposed resolution

Add the same fallbacks to Query, or centralize them.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States mile23 Seattle, WA

    I discovered this while trying to develop my own content entity type in Drupal 10.2.

    I am unable to uninstall the module because it says things like this:

    % ddev drush pm-uninstall my_module
    
    In Query.php line 104:
                                                               
      No base table for my_entity, invalid query.
    

    +1 on #2 to make table discovery consistent.

Production build 0.71.5 2024