When adding a relationship in views on an entity reference base field that has a cardinality that is unlimited (or larger than one) the query fires an sql error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_table__referenced_entity.referenced_entity' in 'where clause': SELECT entity_table.created AS entity_table_created, entity_table.id AS id FROM {entity_table} entity_table LEFT JOIN {entity_table__referenced_entity} entity_table__referenced_entity ON entity_table.id = entity_table__referenced_entity.entity_id AND entity_table__referenced_entity.deleted = :views_join_condition_0 WHERE (( (entity_table__referenced_entity.referenced_entity = :db_condition_placeholder_1) )) ORDER BY entity_table_created DESC LIMIT 6 OFFSET 0; Array ( [:db_condition_placeholder_1] => 1 [:views_join_condition_0] => 0 )
From what i can tell the join is done on the inexistent field
entity_table__referenced_entity.referenced_entity instead of entity_table__referenced_entity.referenced_entity_target_id
This happens only when the field is a base field. I have replicated the conditions with the same field added to a bundle of the entity and the join is made on the correct field and the query runs correctly
Steps to reproduce:
1. Define a custom content entity type
2. Attach to it an entity reference field as a base field. Set cardinality to -1.
3. Make a view of items of that entity and add a relation to the entity type referenced in the field
Comments
Comment #2
jhedstromComment #3
geekygnr CreditAttribution: geekygnr at GiantGoat Web Development Inc. commentedAfter finding this problem I updated to 8.2.3 in hopes that a fix was given but it seems to have the same problem.
Comment #4
geekygnr CreditAttribution: geekygnr at GiantGoat Web Development Inc. commentedI tried to do this
But it was breaking so many tests that I am not sure if this is where the actual problem is. It could be a problem with the entity definition or how the entities are created once defined.
Comment #5
geekygnr CreditAttribution: geekygnr at GiantGoat Web Development Inc. commentedDuplicate of https://www.drupal.org/node/2795455
Comment #6
geekygnr CreditAttribution: geekygnr at GiantGoat Web Development Inc. commented