0

I have a View with relationships (to referenced entities) that have translations. This causes duplicate rows in the results for each of the referenced entities translations.

You probably know of this behavior as it is the same as in this bug: https://www.drupal.org/node/2582535

I have tried to find a workaround (distinctt query, aggregation, filter by distinct count=1, filter by page language) but with no result. If you know of an alternative i would be happy and grateful to know it.

View Query:

SELECT DISTINCT node_field_data.nid AS nid, node_field_data.title AS node_field_data_title, node__field_description.field_description_value AS node__field_description_field_description_value, node__field_requirement_priority.field_requirement_priority_value AS node__field_requirement_priority_field_requirement_priority_, node_field_data_node__field_required_by_sub.title AS node_field_data_node__field_required_by_sub_title, field_submodules_node_field_data.title AS field_submodules_node_field_data_title, field_submodules_node_field_data__node__field_order.field_order_value AS field_submodules_node_field_data__node__field_order_field_or, node_field_data_node__field_required_by_sub__node__field_order.field_order_value AS node_field_data_node__field_required_by_sub__node__field_ord, node__field_order.field_order_value AS node__field_order_field_order_value, MIN(node_field_data.nid) AS nid_1, MIN(node_field_data_node__field_required_by_sub.nid) AS node_field_data_node__field_required_by_sub_nid, MIN(node_field_data_node__field_dependencies.nid) AS node_field_data_node__field_dependencies_nid, MIN(field_submodules_node_field_data.nid) AS field_submodules_node_field_data_nid FROM {node_field_data} node_field_data LEFT JOIN {node__field_required_by_sub} node__field_required_by_sub ON node_field_data.nid = node__field_required_by_sub.entity_id AND (node__field_required_by_sub.deleted = '0' AND node__field_required_by_sub.langcode = node_field_data.langcode) LEFT JOIN {node_field_data} node_field_data_node__field_required_by_sub ON node__field_required_by_sub.field_required_by_sub_target_id = node_field_data_node__field_required_by_sub.nid LEFT JOIN {node__field_dependencies} node__field_dependencies ON node_field_data.nid = node__field_dependencies.entity_id AND (node__field_dependencies.deleted = '0' AND node__field_dependencies.langcode = node_field_data.langcode) LEFT JOIN {node_field_data} node_field_data_node__field_dependencies ON node__field_dependencies.field_dependencies_target_id = node_field_data_node__field_dependencies.nid LEFT JOIN {node__field_submodules} node_field_data_node__field_required_by_sub__node__field_submodules ON node_field_data_node__field_required_by_sub.nid = node_field_data_node__field_required_by_sub__node__field_submodules.field_submodules_target_id AND node_field_data_node__field_required_by_sub__node__field_submodules.deleted = '0' LEFT JOIN {node_field_data} field_submodules_node_field_data ON node_field_data_node__field_required_by_sub__node__field_submodules.entity_id = field_submodules_node_field_data.nid LEFT JOIN {node__field_description} node__field_description ON node_field_data.nid = node__field_description.entity_id AND (node__field_description.deleted = '0' AND node__field_description.langcode = node_field_data.langcode) LEFT JOIN {node__field_requirement_priority} node__field_requirement_priority ON node_field_data.nid = node__field_requirement_priority.entity_id AND (node__field_requirement_priority.deleted = '0' AND node__field_requirement_priority.langcode = node_field_data.langcode) LEFT JOIN {node__field_order} field_submodules_node_field_data__node__field_order ON field_submodules_node_field_data.nid = field_submodules_node_field_data__node__field_order.entity_id AND (field_submodules_node_field_data__node__field_order.deleted = '0' AND field_submodules_node_field_data__node__field_order.langcode = field_submodules_node_field_data.langcode) LEFT JOIN {node__field_order} node_field_data_node__field_required_by_sub__node__field_order ON node_field_data_node__field_required_by_sub.nid = node_field_data_node__field_required_by_sub__node__field_order.entity_id AND (node_field_data_node__field_required_by_sub__node__field_order.deleted = '0' AND node_field_data_node__field_required_by_sub__node__field_order.langcode = node_field_data_node__field_required_by_sub.langcode) LEFT JOIN {node__field_order} node__field_order ON node_field_data.nid = node__field_order.entity_id AND (node__field_order.deleted = '0' AND node__field_order.langcode = node_field_data.langcode) WHERE (( (node_field_data_node__field_required_by_sub.nid IN('1000', '1010', '1020', '1030', '1040') ) )AND(( (node_field_data.status = '1') AND (node_field_data.type IN ('e_proc_req')) )))AND( (node_field_data_node__field_dependencies.nid IS '') OR (node_field_data_node__field_dependencies.nid IN ('')) ) GROUP BY node_field_data.nid, node_field_data_title, node__field_description_field_description_value, node__field_requirement_priority_field_requirement_priority_, node_field_data_node__field_required_by_sub_title, field_submodules_node_field_data_title, field_submodules_node_field_data__node__field_order_field_or, node_field_data_node__field_required_by_sub__node__field_ord, node__field_order_field_order_value HAVING (( (COUNT(DISTINCT node_field_data.nid) = '1') )) ORDER BY field_submodules_node_field_data__node__field_order_field_or ASC, node_field_data_node__field_required_by_sub__node__field_ord ASC, node__field_order_field_order_value ASC

1

Update: Found a workaround by removing the duplicate rows in pre render. It is not nice but it achieves the wanted result.

function my_module_views_pre_render(ViewExecutable $view) {
if ($view->id() == 'my_view') {
    $newresult = array();
        foreach ($view->result as $row) {
            if (in_array($row->_entity->id(), $newresult)) {
                unset ($view->result[$row->index]);
            }
            else {
            array_push($newresult, $row->_entity->id());
            }
    }
} }
  • Thank you! I was going insane with this problem :) – Chris Jun 3 at 3:35
0

You should definitely create a "translation" filter criteria in your view. I think there should be also a workaround / exact filter to make constraints on relation entities!

  • I dont wan't to filter by language. I would like to show the available translation if it exists or English if not. This works fine from the Language Render Row option. However i receive duplicates for each translated referenced entity. – mrgorski Jul 22 '16 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.