Views "is none of" NOR operator FAILS on multiple values

Fool2 - May 15, 2009 - 17:34
Project:CCK Taxonomy Fields
Version:5.x-1.2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Using this module with views is problematic and inconsistent if you are using the "Is none of" operator.

To reproduce:

With a multiple select CCK taxonomy field, assign at least one node two terms
Place a filter in a view calling that node with the "Is none of" operator and select only ONE of the two terms from that vocabulary. For this to glitch, you must select the "newer" term with the higher TID (lower in the list probably)

I have been trying to find a workaround for a couple of days now. This does NOT happen if I do it with standard taxonomy view (though I am slowly comparing the generated queries to find the bug). Any ideas?

#1

Fool2 - May 16, 2009 - 20:12

Okay, I've fixed this issue for myself but I'm not sure if it 1) breaks the rest of the operators or 2) will work for multiple fields

But for those of you who do run into this problem and need at least the start of a solution, I will post it below.

I got the original code from examining views_taxonomy's custom tid handler after seeing that it formed a much cleaner SQL query

  'handler' => 'cck_taxonomy_views_handler',

First I reference a new handler in cck_taxonomy around line 229
function cck_taxonomy_views_handler($op, $filter, $filterinfo, &$query){
_views_cck_taxonomy_add($filter['operator'], $filter['value'], $filter['options'], $query);
}

function _views_cck_taxonomy_add($op, $value, $depth, &$query){
if ($op == 'NOR') {
    //ignore the depth for this case
    $table_data = _views_get_tables();
    $joininfo = $table_data['NAMEOFFIELD']['join'];
    $joininfo['extra']['NAMEOFCOLUMN'] = $value;
    $num = $query->add_table('NAME OF FIELD', false, 1, $joininfo);
    $tablename = $query->get_table_name('NAMEOFFIELD', $num);
    $query->add_where("$tablename.NAMEOFCOLUMN IS NULL");
  }
}

NAMEOFFIELD is something like cck_taxonomy_field_*
NAMEOFCOLUMN is something like field_* and is the name of the cck column in the database (it should end with _tid in our case). There should be a way to find these automatically to make this work with multiple fields etc but I don't have the time or necessity to develop that right now.

#2

Fool2 - August 13, 2009 - 18:37

This behavior is also present in the node reference CCK fields for views.

 
 

Drupal is a registered trademark of Dries Buytaert.