views_handler_argument_many_to_one::query() starts with

if (empty($this->argument)) {
  (TREAT as 'where field IS NULL')
  return;
}

So you can't provide an actual value of 0 (or string '0') for the argument - will be treated as NULL

Comments

yched’s picture

consistently, the link generated by views_handler_argument_many_to_one::summary_argument() for the 'no value' item in summaries is currently [views_url]/0, so you get two different items in summaries (one for 'no value', one for '0'), with the same url.

Visible with very latest CCK (as of today), using a number field with a list of allowed values that includes 0.

merlinofchaos’s picture

The many to one filter was built on the assumption that you're using a 'serial' type field as the key, meaning values > 1. Both 0 and -1 are actually reserved by this handler.

I'm not sure what good alternatives are, honestly. I have to pick *some* value to represent no value, and reserve it. If CCK doesn't reserve any value, then you may need to create a subclassed version that strips out these features and simply doesn't allow the 'no value' case.

Using 0 as an identifier is always somewhat dangerous in Drupal.

merlinofchaos’s picture

Ok, I think the proper solution is this:

Create a field in the definition that says what the uncategorized value is. Taxonomy can use 0. If this is not present, then uncategorized should become illegal and the query should specifically disallow NULLs.

Anyone care to work on this?

raspberryman’s picture

I ran across this when a custom default argument plugin was feeding a CCK number field argument. While this isn't a long term solution, I'd thought I'd post my quick fix - a little argument handler extension...

// A copy of views_handler_argument_many_to_one
class my_handler_argument_many_to_one extends views_handler_argument_many_to_one {

  function query() {
    if (empty($this->argument)) {
      parent::ensure_my_table();
      $this->query->add_where(0, "$this->table_alias.$this->real_field = 0"); // Or whatever you need for your purposes
      return;
    }

    if (!empty($this->options['break_phrase'])) {
      views_break_phrase($this->argument, $this);
    }
    else {
      $this->value = array($this->argument);
      $this->operator = 'or';
    }

    $this->helper->add_filter();
  }
}
dawehner’s picture

Status: Active » Fixed

This is now fixed. Taxonomy counts 0 as empty now.


  // tid field
  $data['term_data']['tid'] = array(
    'title' => t('Term ID'),
    'help' => t('The taxonomy term ID'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
      'skip base' => array('node', 'node_revision'),
      'zero is null' => TRUE,
    ),

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.