Problem/Motivation
Adding a views relationship to a field that references a config entity does not work.
Proposed resolution
Remove the option to create a views relationship with the config entity as there is no base table to join.
Remaining tasks
Add an update path to refresh the views data.
API changes
API clean up, a user can't add a relationship to config entity via UI anymore.
Data model changes
None.
Release notes snippet
N/A
------
Original IS:
Dears,
I am trying to use contextual filters with relationships and have the error below (with the relationships):
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'movadomfpadrupal._taxonomy_term__field_domaine' doesn't exist: SELECT node_field_data.langcode AS node_field_data_langcode, node_field_data.title AS node_field_data_title, node_field_data.nid AS nid, taxonomy_term_field_data_node__field_population.tid AS taxonomy_term_field_data_node__field_population_tid FROM {node_field_data} node_field_data LEFT JOIN {node__field_population} node__field_population ON node_field_data.nid = node__field_population.entity_id AND (node__field_population.deleted = :views_join_condition_0 AND node__field_population.langcode = node_field_data.langcode) LEFT JOIN {taxonomy_term_field_data} taxonomy_term_field_data_node__field_population ON node__field_population.field_population_target_id = taxonomy_term_field_data_node__field_population.tid LEFT JOIN {taxonomy_term__field_domaine} taxonomy_term_field_data_node__field_population__taxonomy_term__field_domaine ON taxonomy_term_field_data_node__field_population.tid = taxonomy_term_field_data_node__field_population__taxonomy_term__field_domaine.entity_id AND (taxonomy_term_field_data_node__field_population__taxonomy_term__field_domaine.deleted = :views_join_condition_2 AND taxonomy_term_field_data_node__field_population__taxonomy_term__field_domaine.langcode = taxonomy_term_field_data_node__field_population.langcode) LEFT JOIN {} _taxonomy_term__field_domaine ON taxonomy_term_field_data_node__field_population__taxonomy_term__field_domaine.field_domaine_target_id = _taxonomy_term__field_domaine.id WHERE (( (node_field_data.status = :db_condition_placeholder_4) AND (node_field_data.type IN (:db_condition_placeholder_5)) )) ORDER BY node_field_data_title ASC; Array ( [:db_condition_placeholder_4] => 1 [:db_condition_placeholder_5] => service [:views_join_condition_0] => 0 [:views_join_condition_2] => 0 )
I have services contents associated with taxonomy terms (populations) using an entity reference field (field_population).
"Populations" taxomony are associated to domain entries (https://www.drupal.org/project/domain) using a reference field (field_domaine).
In my view (called "services" which displays services contents) when I add the relationship to the "Populations" taxonomy terms, everyhtning goes well.
When I add the relationship to the reference to a domain field, I go the error.
What am I doing wrong ?
View details is in attachment
Thanks for your help?
Comment | File | Size | Author |
---|---|---|---|
#29 | 2838555-29.patch | 6.85 KB | Lendude |
Comments
Comment #2
LendudeMoving to the Views core queue for now, might need to go to the Domain queue.
LEFT JOIN {} _taxonomy_term__field_domaine
For some reason it seems to be trying to join an empty string as the table.
We need some steps to reproduce for this, not sure if this is a Views thing or a Domain thing.
Comment #3
dawehnerLet's set (postponed (maintainer needs more info)).
Comment #4
superlolo95 CreditAttribution: superlolo95 commentedDears,
After further testing.
Test 1 passed
Test 2 passed
Test 3 failed
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'movadomfpadrupal._taxonomy_term__field_reference' doesn't exist: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {node_field_data} node_field_data LEFT JOIN {node__field_population} node__field_population ON node_field_data.nid = node__field_population.entity_id AND (node__field_population.deleted = :views_join_condition_0 AND node__field_population.langcode = node_field_data.langcode) LEFT JOIN {taxonomy_term_field_data} taxonomy_term_field_data_node__field_population ON node__field_population.field_population_target_id = taxonomy_term_field_data_node__field_population.tid LEFT JOIN {taxonomy_term__field_reference} taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference ON taxonomy_term_field_data_node__field_population.tid = taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference.entity_id AND (taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference.deleted = :views_join_condition_2 AND taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference.langcode = taxonomy_term_field_data_node__field_population.langcode) LEFT JOIN {} _taxonomy_term__field_reference ON taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference.field_reference_target_id = _taxonomy_term__field_reference.id WHERE (( (node_field_data.type IN (:db_condition_placeholder_0)) ))) subquery; Array ( [:db_condition_placeholder_0] => article [:views_join_condition_0] => 0 [:views_join_condition_2] => 0 )
Test 4 failed
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'movadomfpadrupal._taxonomy_term__field_reference_to_block' doesn't exist: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {node_field_data} node_field_data LEFT JOIN {node__field_population} node__field_population ON node_field_data.nid = node__field_population.entity_id AND (node__field_population.deleted = :views_join_condition_0 AND node__field_population.langcode = node_field_data.langcode) LEFT JOIN {taxonomy_term_field_data} taxonomy_term_field_data_node__field_population ON node__field_population.field_population_target_id = taxonomy_term_field_data_node__field_population.tid LEFT JOIN {taxonomy_term__field_reference_to_block} taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference_to_block ON taxonomy_term_field_data_node__field_population.tid = taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference_to_block.entity_id AND (taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference_to_block.deleted = :views_join_condition_2 AND taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference_to_block.langcode = taxonomy_term_field_data_node__field_population.langcode) LEFT JOIN {} _taxonomy_term__field_reference_to_block ON taxonomy_term_field_data_node__field_population__taxonomy_term__field_reference_to_block.field_reference_to_block_target_id = _taxonomy_term__field_reference_to_block.id WHERE (( (node_field_data.type IN (:db_condition_placeholder_0)) ))) subquery; Array ( [:db_condition_placeholder_0] => article [:views_join_condition_0] => 0 [:views_join_condition_2] => 0 )
I suppose that if the reference is not a a reference to somathing is categorized as "Content" (but something that is categorized as a "Configuration"), it fails.
It seems not related to the domain module but to views.
Regards
Comment #5
superlolo95 CreditAttribution: superlolo95 commentedComment #10
dchaffin CreditAttribution: dchaffin commentedI'm having this same issue as well ... trying to create a relationship to a domain access record.
JOIN {} _commerce_store__field_store_domain
Comment #14
pameeela CreditAttribution: pameeela commentedUpdating the IS based on #4 where steps to reproduce were provided.
Comment #15
pameeela CreditAttribution: pameeela commentedComment #16
pameeela CreditAttribution: pameeela commentedComment #17
LendudeClosed #2915191: Configuration entity reference field relationship throws error. as a duplicate
Comment #18
LendudeHere we go with a 'fix'. This is in line with what is being done in
\Drupal\views\EntityViewsData::processViewsDataForEntityReference
, why is this done twice I hear you thinking...that is an excellent question, but out of scope here I think.Since there is no real way to fix this (there is after all nothing to join on), the best we can do is remove the relationship.
If tested the effect this has on existing relationships and it goes from throwing an SQL error to having a Broken/missing handler.
So we could add an upgrade path that cleans up these relationships, but I think that we can be pretty sure this is not being used in the wild, well not successfully anyway....
Bumping to major because it leads to a fatal error through normal use of the UI.
Comment #20
Lendudeno idea where this bit came from, but it's unrelated
Comment #21
Lendudeaddresses #20
Comment #22
jibranThis is not major IMO, even if it is fatal you are doing the thing you are not supposed to do. A simple post-update hook would suffice to update the views data cache.
Comment #23
jibranUpdated IS.
Comment #24
phenaproximaShould this be using ContentEntityTypeInterface, rather than the concrete class?
Comment #25
Lendude#24 yes it should. Blind c/p from the other instance
Comment #27
LendudeUnrelated fail
Comment #28
LendudeHmm NW for the update hook
Comment #29
LendudeAnd here we go with an empty update to clear the Views data.
Comment #30
jibranThis fix is now same as
\Drupal\views\EntityViewsData::processViewsDataForEntityReference
so this is fine but we could reduce the patch size by using following code:As this code test shows we are removing the support for config entity relationships. Currently, as soon as you add a relationship with config entity you see the following error:
And view stops showing results. You can still save the view with the error but the view will not show results and generate an error on every page load.
After applying the patch you see
but without any error and view start showing results and there is no error on the page load.
Given above I'd say an empty hook is the best way forward rather than removing broken views relationships from already broken views.
Comment #32
catchCommitted/pushed to 9.1.x, thanks!