I have a view which filters the nodes I want to diaplay based on a Taxonomy term argument taken from the URL. Also, I have two groups of filters, linked by an OR operator between them but with AND operator within each group. Turns out, the argument is only applied to the first group and not to both of them, which was the behavior I expected. I understand this as an issue. How can I address it?

This is the view:

SELECT node_data_field_foto.field_foto_fid AS node_data_field_foto_field_foto_fid,
node_data_field_foto.field_foto_list AS node_data_field_foto_field_foto_list,
node_data_field_foto.field_foto_data AS node_data_field_foto_field_foto_data,
node.nid AS nid,
node.type AS node_type,
node.vid AS node_vid,
node_data_field_flg_analisis.field_image_fid AS node_data_field_flg_analisis_field_image_fid,
node_data_field_flg_analisis.field_image_list AS node_data_field_flg_analisis_field_image_list,
node_data_field_flg_analisis.field_image_data AS node_data_field_flg_analisis_field_image_data,
node.title AS node_title,
users.name AS users_name,
users.uid AS users_uid,
node.changed AS node_changed,
node_revisions.teaser AS node_revisions_teaser,
node_revisions.format AS node_revisions_format
FROM node node

LEFT JOIN content_type_showcase_with_image node_data_field_flg_analisis ON node.vid = node_data_field_flg_analisis.vid

LEFT JOIN term_node term_node ON node.vid = term_node.vid

INNER JOIN term_data term_data ON term_node.tid = term_data.tid

LEFT JOIN content_type_story node_data_field_foto ON node.vid = node_data_field_foto.vid

INNER JOIN users users ON node.uid = users.uid

LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid

WHERE ((node.status = 1) AND (node.type in ('showcase_with_image')) AND (node_data_field_flg_analisis.field_flg_analisis_value = 0) AND (term_data.name = 'PremierLeague'))
OR ((node.status = 1) AND (node.type in ('story')))
ORDER BY node_changed DESC

As you can see in the "where" part, term_data.name = 'PremierLeague' filter (this is the argument) is only applied to the first group --> (node.status = 1) AND (node.type in ('showcase_with_image')) AND (node_data_field_flg_analisis.field_flg_analisis_value = 0

and I need it to be applied to second as well --> (node.status = 1) AND (node.type in ('story')

Comments

slashrsm’s picture

Assigned: Unassigned » esmerel

It seems like a bug, but since I am not sure I assign this to esmerel to figure it out.

merlinofchaos’s picture

Helloooooo design flaw. :/

For now your only acceptable workaround may be to use hook_views_query_alter to add your argument into the second group, because...I don't have any idea how to fix this in the design right now. Will require some serious thinking.

esmerel’s picture

Assigned: esmerel » Unassigned
ayukko’s picture

oooook
I am a newbie so I have no idea about how to use that function. Would someone please point me to a manual or something like that to help me out unraveling Views core? Thanks in advance!

slashrsm’s picture

You can implement this hook in your module to make modifications to query that views builds for you.

See API: http://drupalcontrib.org/api/function/hook_views_query_alter/6

ayukko’s picture

Thanks!!

iamjon’s picture

Category: support » bug

assigning this to merlinofchaos for review.
changing status based on comment #2

zambrey’s picture

Subscribing. Also applies to 7.x-3.x branch

zambrey’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

Funny thing just happened. I tried using hook_views_query_alter() as mentioned in #2 to somehow alter arguments.
So in my case (7.x-3.x) I try to set "Has taxonomy term ID (with depth)" contextual filter apart from normal filter which is Published, Node type = "product view" and term = 6 (from other category). So having set depth to 10 the subquery related to taxonomy is as follows (for contextual filter = 16):

SELECT tn.nid AS nid FROM {taxonomy_index} tn
LEFT OUTER JOIN {taxonomy_term_hierarchy} th ON th.tid = tn.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th1 ON th.parent = th1.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th2 ON th1.parent = th2.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th3 ON th2.parent = th3.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th4 ON th3.parent = th4.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th5 ON th4.parent = th5.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th6 ON th5.parent = th6.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th7 ON th6.parent = th7.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th8 ON th7.parent = th8.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th9 ON th8.parent = th9.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th10 ON th9.parent = th10.tid
WHERE ( (tn.tid = '16') OR (th1.tid = '1') OR (th2.tid = 'product_view') OR (th3.tid = '6') OR (th4.tid = '16') OR (th5.tid = '16') OR (th6.tid = '16') OR (th7.tid = '16') OR (th8.tid = '16') OR (th9.tid = '16') OR (th10.tid = '16') )

So it seems like regular filter values are somehow passed to taxonomy subquery as arguments starting from the second.
I'm not familliar with the DBTNG yet but I figured out the way to show arguments from subquery:

function mymodule_views_query_alter(&$view, &$query) {
  if ($view->name == 'products' && $view->current_display == 'block_3') {
  $query2 = $query->where[0]['conditions'][3]['value'];
  dpm($query2->getArguments());
  }
}

And... it is fixed :) All ten arguments are set as "16" but now the query looks like this

SELECT tn.nid AS nid FROM {taxonomy_index} tn
LEFT OUTER JOIN {taxonomy_term_hierarchy} th ON th.tid = tn.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th1 ON th.parent = th1.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th2 ON th1.parent = th2.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th3 ON th2.parent = th3.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th4 ON th3.parent = th4.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th5 ON th4.parent = th5.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th6 ON th5.parent = th6.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th7 ON th6.parent = th7.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th8 ON th7.parent = th8.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th9 ON th8.parent = th9.tid
LEFT OUTER JOIN {taxonomy_term_hierarchy} th10 ON th9.parent = th10.tid
WHERE ( (tn.tid = '16') OR (th1.tid = '16') OR (th2.tid = '16') OR (th3.tid = '16') OR (th4.tid = '1') OR (th5.tid = 'product_view') OR (th6.tid = '6') OR (th7.tid = '16') OR (th8.tid = '16') OR (th9.tid = '16') OR (th10.tid = '16') 

So seems like calling getArguments() itself somehow moved regular filter values by three positions and since I have 3-max depth terms this works for my very case. I know this is temporary "fix" but maybe it will help someone.
I'm moving this issue to 7.x-3.x branch because it looks like most features & bugfixes go there first.

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev

Well you didn't posted your full code, so it's hard to guess where the problem is.

Please do this first.
But in general this issue shouldn't be hijacked, it was against 6.x-3.x
There will be a way to pull filter values from argument so you don't need this anymore.

zambrey’s picture

Sorry for hijacking, I'm quite new at issue queues :(

Not sure what to do next. By full code you mean view export?
Should I post it here or open new issue for that?
I've found #1150788: Filters, contextual filters, and/or together is a mess but it is focused on Documentation and I don't want to hijack things again.

chrisns’s picture

How near are we to having a fix for this to be done through the UI without having to alter stuff in code?

chrisns’s picture

How near are we to having a fix for this to be done through the UI without having to alter stuff in code?

kevinob11’s picture

any movement on this?

dawehner’s picture

Well there is #357082: Pull filter value from an argument? which will probably solve the issue for you as well.

kevinob11’s picture

Yeah that is what I'm doing as a workaround, however because I am also trying to filter on two date fields I'm still at an impasse. The date fields create their own group in the where clause that has its own "or" operator. I think this is a date module issue though, as it used its own and/or handling in previous versions of views that likely need to be removed.

MustangGB’s picture

Status: Active » Closed (won't fix)