Problem/Motivation

I have create a view with a negative depth and I get a SQL error.

Exception in pruebas[pruebas]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tn.entity_id' in 'on clause': SELECT "node_field_data"."created" AS "node_field_data_created", "node_field_data"."nid" AS "nid" FROM "node_field_data" "node_field_data" WHERE ("node_field_data"."status" = :db_condition_placeholder_0) AND ("node_field_data"."nid" IN (SELECT "tn"."nid" AS "nid" FROM "taxonomy_index" "tn" LEFT OUTER JOIN "taxonomy_term__parent" "tp1" ON tn.entity_id = tp1.parent_target_id LEFT OUTER JOIN "taxonomy_term__parent" "tp2" ON tp1.entity_id = tp2.parent_target_id LEFT OUTER JOIN "taxonomy_term__parent" "tp3" ON tp2.entity_id = tp3.parent_target_id LEFT OUTER JOIN "taxonomy_term__parent" "tp4" ON tp3.entity_id = tp4.parent_target_id WHERE ("tn"."tid" = :db_condition_placeholder_1) OR ("tp1"."entity_id" = :db_condition_placeholder_2) OR ("tp2"."entity_id" = :db_condition_placeholder_3) OR ("tp3"."entity_id" = :db_condition_placeholder_4) OR ("tp4"."entity_id" = :db_condition_placeholder_5))) ORDER BY "node_field_data_created" DESC LIMIT 11 OFFSET 0; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 27 [:db_condition_placeholder_2] => 27 [:db_condition_placeholder_3] => 27 [:db_condition_placeholder_4] => 27 [:db_condition_placeholder_5] => 27 ) en main() (linea 19 de /var/www/html/web/index.php).

Steps to reproduce

  1. Create a view.
  2. Add a exposed filter criteria "Content: Has taxonomy terms (with depth)" with a negative value.
  3. Use the exposed filter.

Proposed resolution

The problem is in ShsTaxonomyIndexTidDepth:: query, line 154 to 160.

This code works great in a local instalation:

    elseif ($this->options['depth'] < 0) {

      foreach (range(1, abs($this->options['depth'])) as $key => $count) {

        if($key === 0){

          $subquery->leftJoin('taxonomy_term__parent', "tp$count", "tn.tid = tp$count.parent_target_id");

        }

        else {

          $subquery->leftJoin('taxonomy_term__parent', "tp$count", "$last.entity_id = tp$count.parent_target_id");

        }

        $where->condition("tp$count.entity_id", $this->value, $operator);

        $last = "tp$count";

      }

    }

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork shs-3323584

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

oskar_calvo created an issue. See original summary.

oskar_calvo’s picture

StatusFileSize
new1.04 KB
oskar_calvo’s picture

Status: Active » Patch (to be ported)
oskar_calvo’s picture

Status: Patch (to be ported) » Needs review
heikkiy’s picture

Status: Needs review » Reviewed & tested by the community

We encountered this same issue in a view that was not actually using the view filter but was still encountering the error with a negative depth.

The patch worked so marking this as RTBC.

joseph.olstad’s picture

Thanks for the review, checking patch

joseph.olstad’s picture

Looks good, should go in soon!

heikkiy’s picture

I wonder if it would be a separate issue that the view filter plugin seemed to affect also a view that was not using the Simple hierarchical select selection type but the normal Dropdown? I am not that familiar how the view filters in the core work in the backend but it seems weird that the code execution goes this far to get a SQL error when the selection type is not used.