Sorting not working for relationship field.

Created on 10 June 2021, over 3 years ago
Updated 21 November 2023, about 1 year ago

Steps to reproduce

Content type A
title: string
category: Reference Content type B

Content type B is sorted by draggableviews.

Create a view for content type A and sort by draggableviews of the category field.

Sorting not working!

πŸ› Bug report
Status

Needs review

Version

2.1

Component

Code

Created by

πŸ‡¨πŸ‡³China LukeChen

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.

  • πŸ‡ΊπŸ‡ΈUnited States ultimike Florida, USA

    @el1_1el maybe this will work for you:

        //$def['left_table'] = $this->query->view->storage->get('base_table');
        //$def['left_table'] = $this->relationship ?? $this->query->view->storage->get('base_table');
        //$def['left_field'] = $this->query->view->storage->get('base_field');
        //$def['left_field'] = $this->getJoin()->configuration['left_field'];
    
        if ($this->relationship) {
          $def['left_table'] = $this->relationship;
          $def['left_field'] = $this->getJoin()->configuration['left_field'];
        }
        else {
          $def['left_table'] = $this->query->view->storage->get('base_table');
          $def['left_field'] = $this->query->view->storage->get('base_field');
        }
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 8
    last update over 1 year ago
    1 pass
  • @ultimike opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States ultimike Florida, USA

    Updating branch to 2.1.x-dev.

    MR created - I have confirmed that the code snippet in my previous comment solves my issue of sorting not working when using a Views relationship.

    -mike

  • πŸ‡·πŸ‡ΊRussia vvs Russia

    On version 2.1.3, after #13:

    SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= draggableviews_structure.entity_id AND (draggableviews_structure.view_name ...' at line 12: SELECT "node_field_data_paragraph__field_konfeta__draggableviews_structure"."weight" AS "node_field_data_paragraph__field_konfeta__draggableviews_str", "draggableviews_structure"."weight" AS "draggableviews_structure_weight_1", "paragraphs_item_field_data"."id" AS "id", "node_field_data_paragraph__field_konfeta"."nid" AS "node_field_data_paragraph__field_konfeta_nid", "taxonomy_term_field_data_node_field_data"."tid" AS "taxonomy_term_field_data_node_field_data_tid", COALESCE(draggableviews_structure.weight, -9223372036854775808) AS "draggableviews_structure_weight" FROM "paragraphs_item_field_data" "paragraphs_item_field_data" LEFT JOIN "paragraph__field_konfeta" "paragraph__field_konfeta" ON paragraphs_item_field_data.id = paragraph__field_konfeta.entity_id AND paragraph__field_konfeta.deleted = :views_join_condition_0 INNER JOIN "node_field_data" "node_field_data_paragraph__field_konfeta" ON paragraph__field_konfeta.field_konfeta_target_id = node_field_data_paragraph__field_konfeta.nid INNER JOIN (SELECT "td".*, "tn"."nid" AS "nid" FROM "taxonomy_term_field_data" "td" INNER JOIN "taxonomy_index" "tn" ON "tn"."tid" = "td"."tid" WHERE "td"."vid" IN (:db_condition_placeholder_6)) "taxonomy_term_field_data_node_field_data" ON node_field_data_paragraph__field_konfeta.nid = taxonomy_term_field_data_node_field_data.nid LEFT JOIN "draggableviews_structure" "node_field_data_paragraph__field_konfeta__draggableviews_structure" ON node_field_data_paragraph__field_konfeta.nid = node_field_data_paragraph__field_konfeta__draggableviews_structure.entity_id LEFT JOIN "draggableviews_structure" "draggableviews_structure" ON node_field_data_paragraph__field_konfeta. = draggableviews_structure.entity_id AND (draggableviews_structure.view_name = :views_join_condition_1 AND draggableviews_structure.view_display = :views_join_condition_2) WHERE ("paragraphs_item_field_data"."parent_id" = :db_condition_placeholder_3) AND (("paragraphs_item_field_data"."status" = :db_condition_placeholder_4) AND ("paragraphs_item_field_data"."type" IN (:db_condition_placeholder_5))) ORDER BY "draggableviews_structure_weight" ASC, "draggableviews_structure_weight_1" ASC; Array ( [:db_condition_placeholder_3] => 1363 [:db_condition_placeholder_4] => 1 [:db_condition_placeholder_5] => konfeta [:views_join_condition_0] => 0 [:db_condition_placeholder_6] => fabrics [:views_join_condition_1] => massovoe_redaktirovanie_konfet [:views_join_condition_2] => page_1 )

  • πŸ‡ΊπŸ‡ΈUnited States jmcintyre

    #12 solved the issue for me as well, thanks!

Production build 0.71.5 2024