I have a view that I am using to generate two displays that are shown on a page with quicktabs. The views have a primary (non-exposed) filter for a completion state, which is a Text List field on the Node:
- Planned
- In Progress
- Delayed
- Complete
- Canceled
The View Display is a FooTable (this is unrelated). On one View Display, I set the primary (non-exposed) filter to ONE OF and limit the select list options to 'Planned', 'In Progress' and 'Delayed'. I then add an exposed filter to allow users to further refine the list to one of these three options, so there are two filters for the same field.
I have found that in order for the above to work properly, the non-exposed filter (primary) must be ordered ABOVE the exposed filter.
But things get funny with my second View Display, in which I have a primary (non-exposed) filter to ONE OF 'Complete', 'Canceled' combined with a secondary exposed filter for these two list items. When selecting 'Complete' in the exposed filter, the SQL output shows the following in the query:
LEFT JOIN {field_data_field_permit_status} field_data_field_permit_status2 ON node.nid = field_data_field_permit_status2.entity_id AND field_data_field_permit_status2.field_permit_status_value != 'Complete'
Note that the query is now looking for anything that does NOT have the term 'Complete', which is the opposite of what we want. This is a bug.
A workaround is to change the non-exposed primary filter to select the initial terms through an inverse (IS NOT ONE OF 'Planned', 'In Progress', 'Delayed'). This will then work with a secondary filter of IS ONE OF, however it appears that two filters on a select list IS ONE OF does not work.
Comments
Comment #2
brooke_heaton commentedComment #3
matthiasm11 commentedI can confirm the issue. Quickly investigated the code, but could not find where the LEFT JOIN was added.
I did found this:
The primary (non-exposed) filter adds a WHERE clausule to the query, this is normal behaviour. It will look something like this:
The secondary (exposed) filter, will not add any additional JOINS when it was not used, this is also normal behaviour.
When the secondary (exposed) filter is used, for example the first item is checked (term id 8 in my example), all works fine: an additional where clausule will be added. So we get a where clausule from the primary (non-exposed) filter, and a where clausule from the secondary (exposed) filter. It will look something like this:
But when the last item (term id 111 in my example) is checked, the LEFT JOIN query with impossible filter is added. The query will look something like this:
I retested this a couple of times in different displays with different term id's and can confirm the issue only occurs with the last item of the primary (non-exposed) filter in the WHERE clausule.
Temporary using the described work around: IS NOT ONE OFF in the primary (non-exposed) filter.
Comment #4
mrdalesmith commentedI'm having this issue too, with the exact same impossible JOIN being added to the SQL query. I've added a link to 1309578 as the only reason I need two filters (one exposed, one not) on the same view is to limit the initial results when "Limit to selected items" in the exposed filter doesn't already do this.
Comment #5
mehul.shah commentedYes, this is applicable to the latest version of the Drupal - i.e. 8.7
I am working on taxonomy term reference field "status" attached to a node, I have created a view and applied 2 filters on this field. Out of which one is Non - exposed and other is exposed.
The view works properly when I don't use the exposed filter but as soon as I use the exposed filter it works weirdly. check out the query below for more understanding.
LEFT JOIN {node__field_status} node__field_status2 ON node_field_data.nid = node__field_status2.entity_id AND INNER JOIN {node__field_status} node__field_status ON node_field_data.nid = node__field_status.entity_id AND node__field_status.deleted = '0'
LEFT JOIN {node__field_status} node__field_status2 ON node_field_data.nid = node__field_status2.entity_id AND node__field_status2.field_status_target_id != '5'
The first join is for the Non-exposed filter and the second join is for the exposed filter if you look at the condition of the second join it indicates node__field_status2.field_status_target_id != '5', which is exactly opposite of what i am trying to do.
Comment #6
damienmckennaFYI in Drupal 8 the Views module was added to core. As a result, all issues related to Views for Drupal 8 should be added to the Drupal core issue queue. Hopefully someone will be able to help you there.
Comment #8
krowrof commentedStill occurs in 8.8 - but a work around seems to be to enable "Reduce duplicates" on the exposed filter.
Comment #11
matroskeenIt occurred to me on
8.9.xproject and still reproducible on the latest9.2.x.The problem seems the following:
1) During the processing of the first filter, the active value (which is a value selected in the exposed filter) is saved in this line;
2) For the second filter, this value is retrieved and added as a condition in this line, because in the
$this->handler->view->many_to_one_tablesthis field exlready exists;I'm not familiar with views enough, so I'm not sure what the solution should be.
Steps to reproduce are pretty easy:
1) Install Drupal with Standard profile;
2) Open "People" view (admin/structure/views/view/user_admin_people);
3) Add one more filter for "Role" (should be not exposed) and limit displayed roles;
4) Select any role in the exposed filter "Role";
5) You should see a similar join:
LEFT JOIN {user__roles} "user__roles2" ON users_field_data.uid = user__roles2.entity_id AND user__roles2.roles_target_id != 'administrator'Comment #13
noelia_11 commentedWorkaround at #8 working here!
Comment #15
nnevillBut still occurs in 9.3.2.
But good news – workaround from #8 works but it's important to place non-exposed filter before exposed.
Comment #19
frankdesign commentedIn case someone arrives on this issue page and they are using Grouped Filters, the "Reduce duplicates" options is not available in the UI on Grouped Filters. So as a workaround, you need to revert to a Single Filter, put a tick in "Reduce duplicates" and then recreate the Grouped Filter.
Comment #20
javier_rey commentedI can confirm that this still appears at 10.4.2.