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
Comment #1
slashrsm CreditAttribution: slashrsm commentedIt seems like a bug, but since I am not sure I assign this to esmerel to figure it out.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedHelloooooo 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.
Comment #3
esmerel CreditAttribution: esmerel commentedComment #4
ayukko CreditAttribution: ayukko commentedoooook
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!
Comment #5
slashrsm CreditAttribution: slashrsm commentedYou 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
Comment #6
ayukko CreditAttribution: ayukko commentedThanks!!
Comment #7
iamjon CreditAttribution: iamjon commentedassigning this to merlinofchaos for review.
changing status based on comment #2
Comment #8
zambrey CreditAttribution: zambrey commentedSubscribing. Also applies to 7.x-3.x branch
Comment #9
zambrey CreditAttribution: zambrey commentedFunny 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):
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:
And... it is fixed :) All ten arguments are set as "16" but now the query looks like this
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.
Comment #10
dawehnerWell 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.
Comment #11
zambrey CreditAttribution: zambrey commentedSorry 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.
Comment #12
chrisns CreditAttribution: chrisns commentedHow near are we to having a fix for this to be done through the UI without having to alter stuff in code?
Comment #13
chrisns CreditAttribution: chrisns commentedHow near are we to having a fix for this to be done through the UI without having to alter stuff in code?
Comment #14
kevinob11 CreditAttribution: kevinob11 commentedany movement on this?
Comment #15
dawehnerWell there is #357082: Pull filter value from an argument? which will probably solve the issue for you as well.
Comment #16
kevinob11 CreditAttribution: kevinob11 commentedYeah 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.
Comment #17
MustangGB CreditAttribution: MustangGB commented