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