Hi,

We have a view which uses a term id as an argument to filter on. Nothing especially unusual. The arguments handler code looks like this:

$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'taxonomy_term',
    'validate_fail' => 'ignore',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'poll' => 0,
      'image' => 0,
      'feed' => 0,
      'feed_item' => 0,
      'tellafriend_node' => 0,
      'bestbuy' => 0,
      'contact_ifa' => 0,
      'correspondence' => 0,
      'feature' => 0,
      'feedback' => 0,
      'fivestar' => 0,
      'guide' => 0,
      'interview' => 0,
      'news' => 0,
      'page' => 0,
      'press_release' => 0,
      'promotion' => 0,
      'provider' => 0,
      'report' => 0,
      'research' => 0,
      'story' => 0,
      'tools' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      2 => 2,
      4 => 0,
      5 => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));

When no argument is supplied, the executed query looks like this:

SELECT DISTINCT(node.nid) AS nid,
   node_comment_statistics.comment_count AS node_comment_statistics_comment_count,
   node.created AS node_created,
   node.title AS node_title,
   users.name AS users_name,
   users.uid AS users_uid,
   users.picture AS users_picture
 FROM node node 
 INNER JOIN term_node term_node ON node.vid = term_node.vid
 LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid
 INNER JOIN boston_shared.users users ON node.uid = users.uid
 WHERE (node.status <> 0) AND (node.type in ('feed_item', 'feature', 'interview', 'news', 'press_release', 'report', 'research')) AND (term_node.tid IN (107, 105))
   ORDER BY node_created DESC

But as soon as you pass an argument representing a term ID within the selected vocabulary (in this case vid = 2) then you get this weird additional join in the query which explicitly excludes term 105:

LEFT JOIN term_node term_node2 ON node.vid = term_node2.vid AND term_node2.tid != 105

No matter what the term ID is, if the criteria above are met then this join will appear in the query and block term 105. Very odd! :-/

Comments

merlinofchaos’s picture

I'd have to see the entire view. When combining an argument and a filter both on terms, this is very much the intended behavior, though. It specifically excludes previous terms in the new join. And before you suggest it, no, it can't modify the WHERE clause from the original filter, the two handlers are not able to interact in that fashion.

greg.harvey’s picture

Ah, there is a term filter too. In fact, now you mention it I'm not sure why! Possibly legacy. I don't think it is actually used for anything, so could be removed. I still don't know how it manages to pull that same TID, 105, no matter what the arguments are. Perhaps the term filter is set to something by default and we're just seeing that?

Anyway, this may be enough of a pointer to allow me to sort this out. Thanks.

If I'm still struggling, I'll post the whole view tomorrow (don't have the code handy).

greg.harvey’s picture

Category: bug » support

Switching to a support request, since I now suspect this is not a bug at all.

greg.harvey’s picture

Ok, removing the filter worked, but I still don't quite get why this filter code works the way it does. I'm sure it's perfectly logical, but I don't see it.

We exposed the filter simply as an easy way to get a handle on the term names, so we can remove it and get them another way. Our view path is "insights" and it has a Term ID argument, so if I pass it TID 107, e.g. "insights/107", or just plain 107 on the Views UI page, I get this query back:

SELECT DISTINCT(node.nid) AS nid,
   node_comment_statistics.comment_count AS node_comment_statistics_comment_count,
   node.created AS node_created,
   node.title AS node_title,
   users.name AS users_name,
   users.uid AS users_uid,
   users.picture AS users_picture
 FROM node node 
 INNER JOIN term_node term_node ON node.vid = term_node.vid
 ==> LEFT JOIN term_node term_node2 ON node.vid = term_node2.vid AND term_node2.tid != 105
 LEFT JOIN node_comment_statistics node_comment_statistics ON node.nid = node_comment_statistics.nid
 INNER JOIN boston_shared.users users ON node.uid = users.uid
 WHERE (node.status <> 0) AND (node.type in ('feed_item', 'feature', 'interview', 'news', 'press_release', 'report', 'research')) AND (term_node.tid IN (107, 105)) AND (term_node2.tid = 107)
   ORDER BY node_created DESC

I just don't get why it excludes term 105, regardless of previous selections. I don't understand why this would be happening. It's not in the view code or anything like that, and term 105 is not the previous selection - the previous selection was All.

Full view code is here:

$view = new view;
$view->name = 'latest_insight_items';
$view->description = 'Latest Insight Items';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'comment_count' => array(
    'label' => '',
    'set_precision' => FALSE,
    'precision' => 0,
    'decimal' => '.',
    'separator' => ',',
    'prefix' => '',
    'suffix' => ' Comments',
    'exclude' => 0,
    'id' => 'comment_count',
    'table' => 'node_comment_statistics',
    'field' => 'comment_count',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'created' => array(
    'label' => '',
    'date_format' => 'custom',
    'custom_date_format' => 'd/m/Y, H:ia',
    'exclude' => 0,
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => '',
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'name' => array(
    'label' => '',
    'link_to_user' => 1,
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'picture' => array(
    'label' => '',
    'exclude' => 0,
    'id' => 'picture',
    'table' => 'users',
    'field' => 'picture',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'created' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'tid' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'taxonomy_term',
    'validate_fail' => 'ignore',
    'break_phrase' => 0,
    'add_table' => 0,
    'require_value' => 0,
    'reduce_duplicates' => 0,
    'set_breadcrumb' => 0,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'poll' => 0,
      'image' => 0,
      'feed' => 0,
      'feed_item' => 0,
      'tellafriend_node' => 0,
      'bestbuy' => 0,
      'contact_ifa' => 0,
      'correspondence' => 0,
      'feature' => 0,
      'feedback' => 0,
      'fivestar' => 0,
      'guide' => 0,
      'interview' => 0,
      'news' => 0,
      'page' => 0,
      'press_release' => 0,
      'promotion' => 0,
      'provider' => 0,
      'report' => 0,
      'research' => 0,
      'story' => 0,
      'tools' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      2 => 2,
      4 => 0,
      5 => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'feed_item' => 'feed_item',
      'feature' => 'feature',
      'interview' => 'interview',
      'news' => 'news',
      'press_release' => 'press_release',
      'report' => 'report',
      'research' => 'research',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'tid' => array(
    'operator' => 'or',
    'value' => array(
      105 => 105,
      107 => 107,
    ),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'tid_op',
      'identifier' => 'tid',
      'label' => 'Taxonomy: Term ID',
      'optional' => 1,
      'single' => 1,
      'remember' => 0,
      'reduce' => 0,
    ),
    'type' => 'select',
    'vid' => 2,
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'hierarchy' => 0,
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('use_ajax', TRUE);
$handler->override_option('items_per_page', 5);
$handler->override_option('use_pager', '1');
$handler->override_option('use_more', 1);
$handler->override_option('distinct', 1);
$handler->override_option('style_options', array(
  'grouping' => '',
));
$handler = $view->new_display('block', 'Block', 'block_1');
domesticat’s picture

Status: Active » Closed (fixed)

Closed while closing all Views support requests with no activity for 6 months. If you still need help, you may re-open this issue at any time.