EntityViewsData Column information not available for computed entity reference fields

Created on 30 December 2020, over 3 years ago
Updated 25 March 2024, 3 months ago

Problem/Motivation

Entities that have a computed entity_reference field create a fatal error when using the EntityViewsData class for their views_data handler:

Drupal\Core\Entity\Sql\SqlContentEntityStorageException: Column information not available for the 'location' field. in Drupal\Core\Entity\Sql\DefaultTableMapping->getFieldColumnName() (line 439 of /opt/drupal/web/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php).

It seems that this error happens because EntityViewsData creates reverse relationships for all entity_reference fields and expects the field to be stored in the DB. But since this is a computed entity reference field, there is no DB storage.

Steps to reproduce

Add a computed entity reference field to an entity. Set the views_data handler to EntityViewsData. Clearing cache will display the error.

Proposed resolution

A simple workaround is to disable reverse relationships for computed entity reference fields (including a patch with this approach, but I'm not sure this should considered a final solution).

A complete solution needs to somehow trigger computation of the computed field, but since this likely involves complex business logic, I'm unsure if there is a universal solution. It might require a custom views handler for each field?

Remaining tasks

Test using a computed entity reference field.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Views integration

Created by

πŸ‡ΊπŸ‡ΈUnited States paul121 Spokane, WA

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.

Production build 0.69.0 2024